PluginProbe
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity / 1.19.0
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity v1.19.0
3.3.9 3.3.8 trunk 1.0 1.1.0 1.10.0 1.11.0 1.11.1 1.12.0 1.13.0 1.14.0 1.15.0 1.16.0 1.17.0 1.17.1 1.18.0 1.19.0 1.2.0 1.20.0 1.20.1 1.3.0 1.3.1 1.4.0 1.5.0 1.6.0 All 67 releases
logtivity / Services / Logtivity_Check_For_Disabled_Individual_Logs.php

Logtivity_Check_For_Disabled_Individual_Logs.php in Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity 1.19.0, at Services/Logtivity_Check_For_Disabled_Individual_Logs.php

86 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Logtivity_Check_For_Disabled_Individual_Logs
4 {
5 public function __construct()
6 {
7 add_action('wp_logtivity_instance', [$this, 'handle'], 10, 999);
8 }
9
10 public function handle($Logtivity_Logger)
11 {
12 foreach ($this->getLogsToExclude() as $log) {
13 if ($this->check($Logtivity_Logger, $log)) {
14 $Logtivity_Logger->stop();
15 }
16 }
17
18 foreach ($this->globalLogsToExclude() as $log) {
19 if ($this->check($Logtivity_Logger, $log)) {
20 $Logtivity_Logger->stop();
21 }
22 }
23 }
24
25 public function check($Logtivity_Logger, $log)
26 {
27 $array = explode('&&', $log);
28
29 if (isset($array[0]) && isset($array[1])) {
30 if (trim($array[0]) === '*' && trim($array[1]) === '*') {
31 return;
32 }
33 if ($this->matches($Logtivity_Logger->action, $array[0]) && $this->matches($Logtivity_Logger->context, $array[1])) {
34 return true;
35 }
36 } elseif(isset($array[0])) {
37 if (trim($array[0]) === '*') {
38 return;
39 }
40 if ($this->matches($Logtivity_Logger->action, $array[0])) {
41 return true;
42 }
43 }
44 return false;
45 }
46
47 private function matches($keyword, $disabledKeyword)
48 {
49 $keyword = trim(strtolower($keyword));
50 $disabledKeyword = trim(strtolower($disabledKeyword));
51
52 if ($disabledKeyword === '*') {
53 return true;
54 }
55
56 if (strpos($disabledKeyword, '*') !== false) {
57 return strpos($keyword, str_replace('*', '', $disabledKeyword)) !== false;
58 }
59
60 return $keyword == $disabledKeyword;
61 }
62
63 private function getLogsToExclude()
64 {
65 $value = (new Logtivity_Options)->getOption('logtivity_disable_individual_logs');
66
67 if ($value == '') {
68 return [];
69 }
70
71 return preg_split("/\\r\\n|\\r|\\n/", $value);
72 }
73
74 public function globalLogsToExclude()
75 {
76 $value = (new Logtivity_Options)->getOption('logtivity_global_disabled_logs');
77
78 if ($value == '') {
79 return [];
80 }
81
82 return preg_split("/\\r\\n|\\r|\\n/", $value);
83 }
84 }
85
86 $CheckForDisabledIndividualLogs = new Logtivity_Check_For_Disabled_Individual_Logs;