forked from simpleanalytics/wordpress-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrackingRules.php
More file actions
41 lines (29 loc) · 870 Bytes
/
Copy pathTrackingRules.php
File metadata and controls
41 lines (29 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace SimpleAnalytics;
class TrackingRules
{
protected $settings;
public function __construct(WordPressSettings $settings)
{
$this->settings = $settings;
}
public function hasExcludedIp(): bool
{
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? ($_SERVER['REMOTE_ADDR'] ?? null);
if (empty($ip)) return false;
$list = $this->settings->array(SettingName::EXCLUDED_IP_ADDRESSES);
return in_array($ip, $list);
}
public function hasExcludedUserRole(): bool
{
if (! is_user_logged_in()) {
return false;
}
$needle = $this->settings->array(SettingName::EXCLUDED_ROLES);
if ($needle === []) {
return true;
}
$current = wp_get_current_user()->roles;
return array_intersect($needle, $current) !== [];
}
}