| 1 |
<?php |
| 2 |
|
| 3 |
namespace SimpleAnalytics; |
| 4 |
|
| 5 |
class TrackingRules |
| 6 |
{ |
| 7 |
protected $settings; |
| 8 |
|
| 9 |
public function __construct(WordPressSettings $settings) |
| 10 |
{ |
| 11 |
$this->settings = $settings; |
| 12 |
} |
| 13 |
|
| 14 |
public function hasExcludedIp(): bool |
| 15 |
{ |
| 16 |
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR']; |
| 17 |
|
| 18 |
if (empty($ip)) return false; |
| 19 |
|
| 20 |
$list = $this->settings->array(SettingName::EXCLUDED_IP_ADDRESSES); |
| 21 |
|
| 22 |
return in_array($ip, $list); |
| 23 |
} |
| 24 |
|
| 25 |
public function hasExcludedUserRole(): bool |
| 26 |
{ |
| 27 |
if (! is_user_logged_in()) { |
| 28 |
return false; |
| 29 |
} |
| 30 |
|
| 31 |
$needle = $this->settings->array(SettingName::EXCLUDED_ROLES); |
| 32 |
|
| 33 |
if ($needle === []) { |
| 34 |
return true; |
| 35 |
} |
| 36 |
|
| 37 |
$current = wp_get_current_user()->roles; |
| 38 |
|
| 39 |
return array_intersect($needle, $current) !== []; |
| 40 |
} |
| 41 |
} |
| 42 |
|