| 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($keyword1, $disabledKeyword) |
| 48 |
{ |
| 49 |
$disabledKeyword = trim($disabledKeyword); |
| 50 |
|
| 51 |
if ($disabledKeyword === '*') { |
| 52 |
return true; |
| 53 |
} |
| 54 |
|
| 55 |
return strtolower(trim($keyword1)) == strtolower($disabledKeyword); |
| 56 |
} |
| 57 |
|
| 58 |
private function getLogsToExclude() |
| 59 |
{ |
| 60 |
$value = (new Logtivity_Options)->getOption('logtivity_disable_individual_logs'); |
| 61 |
|
| 62 |
if ($value == '') { |
| 63 |
return []; |
| 64 |
} |
| 65 |
|
| 66 |
return preg_split("/\\r\\n|\\r|\\n/", $value); |
| 67 |
} |
| 68 |
|
| 69 |
public function globalLogsToExclude() |
| 70 |
{ |
| 71 |
$value = (new Logtivity_Options)->getOption('logtivity_global_disabled_logs'); |
| 72 |
|
| 73 |
if ($value == '') { |
| 74 |
return []; |
| 75 |
} |
| 76 |
|
| 77 |
return preg_split("/\\r\\n|\\r|\\n/", $value); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
$CheckForDisabledIndividualLogs = new Logtivity_Check_For_Disabled_Individual_Logs; |