| 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 |
$array = explode('&&', $log); |
| 14 |
|
| 15 |
if (isset($array[0]) && isset($array[1])) { |
| 16 |
if ($this->matches($Logtivity_Logger->action, $array[0]) && $this->matches($Logtivity_Logger->context, $array[1])) { |
| 17 |
$Logtivity_Logger->stop(); |
| 18 |
} |
| 19 |
} elseif(isset($array[0])) { |
| 20 |
if ($this->matches($Logtivity_Logger->action, $array[0])) { |
| 21 |
$Logtivity_Logger->stop(); |
| 22 |
} |
| 23 |
} |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
private function matches($keyword1, $keyword2) |
| 28 |
{ |
| 29 |
return strpos(trim($keyword1), trim($keyword2)) !== false; |
| 30 |
} |
| 31 |
|
| 32 |
private function getLogsToExclude() |
| 33 |
{ |
| 34 |
$value = (new Logtivity_Options)->getOption('logtivity_disable_individual_logs'); |
| 35 |
|
| 36 |
if ($value == '') { |
| 37 |
return []; |
| 38 |
} |
| 39 |
|
| 40 |
return preg_split("/\\r\\n|\\r|\\n/", $value); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
$CheckForDisabledIndividualLogs = new Logtivity_Check_For_Disabled_Individual_Logs; |