| @@ -5,32 +5,29 @@ | ||
| 5 | 5 | class TrackingPolicy |
| 6 | 6 | { |
| 7 | 7 | public function shouldCollectAnalytics(): bool |
| 8 | 8 | { |
| 9 | - if ($this->isClientIpExcluded()) { | |
| 9 | + if (Setting::boolean(SettingName::ENABLED, true) === false) { | |
| 10 | 10 | return false; |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | + if ($this->clientIpExcluded($_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'])) { | |
| 14 | + return false; | |
| 15 | + } | |
| 16 | + | |
| 13 | 17 | if (! is_user_logged_in()) { |
| 14 | 18 | return true; |
| 15 | 19 | } |
| 16 | 20 | |
| 17 | - return ! $this->containsExcludedRole(); | |
| 21 | + return ! $this->containsExcludedRole(wp_get_current_user()->roles); | |
| 18 | 22 | } |
| 19 | 23 | |
| 20 | - protected function isClientIpExcluded(): bool | |
| 24 | + protected function clientIpExcluded(string $ip): bool | |
| 21 | 25 | { |
| 22 | - $ip = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR']; | |
| 23 | - | |
| 24 | - if (empty($ip)) return false; | |
| 25 | - | |
| 26 | 26 | return in_array($ip, Setting::array(SettingName::EXCLUDED_IP_ADDRESSES)); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - protected function containsExcludedRole(): bool | |
| 29 | + protected function containsExcludedRole(array $roles): bool | |
| 30 | 30 | { |
| 31 | - $currentRoles = wp_get_current_user()->roles; | |
| 32 | - $excludedRoles = Setting::array(SettingName::EXCLUDED_ROLES); | |
| 33 | - | |
| 34 | - return array_intersect($excludedRoles, $currentRoles) !== []; | |
| 31 | + return array_intersect(Setting::array(SettingName::EXCLUDED_ROLES), $roles) !== []; | |
| 35 | 32 | } |
| 36 | 33 | } |