PluginProbe
Simple Analytics / 1.61
Simple Analytics v1.61
1.109 1.108 1.107 1.106 1.73 1.74 1.75 1.76 1.77 1.78 1.79 1.8 1.80 1.81 1.82 1.83 1.84 1.85 1.86 1.87 1.88 1.89 1.9 1.90 1.91 All 98 releases
← All changes | src/TrackingPolicy.php +5 -12 1.891.61 View file →
@@ -5,9 +5,9 @@
5 5 class TrackingPolicy
6 6 {
7 7 public function shouldCollectAnalytics(): bool
8 8 {
9 - if ($this->isClientIpExcluded()) {
9 + if ($this->clientIpExcluded($_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'])) {
10 10 return false;
11 11 }
12 12
13 13 if (! is_user_logged_in()) {
@@ -13,24 +13,17 @@
13 13 if (! is_user_logged_in()) {
14 14 return true;
15 15 }
16 16
17 - return ! $this->containsExcludedRole();
17 + return ! $this->containsExcludedRole(wp_get_current_user()->roles);
18 18 }
19 19
20 - protected function isClientIpExcluded(): bool
20 + protected function clientIpExcluded(string $ip): bool
21 21 {
22 - $ip = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'];
23 -
24 - if (empty($ip)) return false;
25 -
26 22 return in_array($ip, Setting::array(SettingName::EXCLUDED_IP_ADDRESSES));
27 23 }
28 24
29 - protected function containsExcludedRole(): bool
25 + protected function containsExcludedRole(array $roles): bool
30 26 {
31 - $currentRoles = wp_get_current_user()->roles;
32 - $excludedRoles = Setting::array(SettingName::EXCLUDED_ROLES);
33 -
34 - return array_intersect($excludedRoles, $currentRoles) !== [];
27 + return array_intersect(Setting::array(SettingName::EXCLUDED_ROLES), $roles) !== [];
35 28 }
36 29 }