| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plugin Name: Logtivity |
| 5 |
* Plugin URI: https://logtivity.io |
| 6 |
* Description: Dedicated Event Monitoring for WordPress using Logtivity.io. |
| 7 |
* Version: 1.1.0 |
| 8 |
* Author: Logtivity |
| 9 |
*/ |
| 10 |
|
| 11 |
class Logtivity |
| 12 |
{ |
| 13 |
/** |
| 14 |
* List all classes here with their file paths. Keep class names the same as filenames. |
| 15 |
* |
| 16 |
* @var array |
| 17 |
*/ |
| 18 |
private $dependancies = [ |
| 19 |
'Helpers/Helpers', |
| 20 |
'Helpers/Logtivity_Wp_User', |
| 21 |
'Admin/Logtivity_Options', |
| 22 |
'Admin/Logtivity_Admin', |
| 23 |
'Services/Logtivity_Log_API', |
| 24 |
'Services/Logtivity_Logger', |
| 25 |
'Helpers/Logtivity_Log_Global_Function', |
| 26 |
'Logs/Logtivity_Abstract_Logger', |
| 27 |
]; |
| 28 |
|
| 29 |
/** |
| 30 |
* |
| 31 |
* Log classes |
| 32 |
* |
| 33 |
*/ |
| 34 |
private $logClasses = [ |
| 35 |
'Logs/Core/Logtivity_Post', |
| 36 |
'Logs/Core/Logtivity_User', |
| 37 |
'Logs/Core/Logtivity_Core', |
| 38 |
'Logs/Core/Logtivity_Theme', |
| 39 |
'Logs/Core/Logtivity_Plugin', |
| 40 |
]; |
| 41 |
|
| 42 |
/** |
| 43 |
* List all integration dependancies |
| 44 |
* |
| 45 |
* @var array |
| 46 |
*/ |
| 47 |
private $integrationDependancies = [ |
| 48 |
'WP_DLM' => [ |
| 49 |
'Logs/Download_Monitor/Logtivity_Download_Monitor', |
| 50 |
], |
| 51 |
'MeprCtrlFactory' => [ |
| 52 |
'Logs/Memberpress/Logtivity_Memberpress', |
| 53 |
] |
| 54 |
]; |
| 55 |
|
| 56 |
public function __construct() |
| 57 |
{ |
| 58 |
$this->loadDependancies(); |
| 59 |
|
| 60 |
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), [$this, 'addSettingsLinkFromPluginsPage'] ); |
| 61 |
} |
| 62 |
|
| 63 |
public static function log($action = null, $meta = null, $user_id = null) |
| 64 |
{ |
| 65 |
return Logtivity_Logger::log($action, $meta, $user_id); |
| 66 |
} |
| 67 |
|
| 68 |
public function loadDependancies() |
| 69 |
{ |
| 70 |
foreach ($this->dependancies as $filePath) |
| 71 |
{ |
| 72 |
$this->loadFile($filePath); |
| 73 |
} |
| 74 |
|
| 75 |
$this->maybeLoadLogClasses(); |
| 76 |
|
| 77 |
$this->loadIntegrationDependancies(); |
| 78 |
} |
| 79 |
|
| 80 |
public function maybeLoadLogClasses() |
| 81 |
{ |
| 82 |
if ($this->defaultLoggingDisabled()) { |
| 83 |
return; |
| 84 |
} |
| 85 |
|
| 86 |
foreach ($this->logClasses as $filePath) |
| 87 |
{ |
| 88 |
$this->loadFile($filePath); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Is the default Event logging from within the plugin enabled |
| 94 |
* |
| 95 |
* @return bool |
| 96 |
*/ |
| 97 |
public function defaultLoggingDisabled() |
| 98 |
{ |
| 99 |
return (new Logtivity_Options)->getOption('logtivity_disable_default_logging'); |
| 100 |
} |
| 101 |
|
| 102 |
public function loadIntegrationDependancies() |
| 103 |
{ |
| 104 |
foreach ($this->integrationDependancies as $key => $value) |
| 105 |
{ |
| 106 |
if (class_exists($key)) { |
| 107 |
foreach ($value as $filePath) |
| 108 |
{ |
| 109 |
$this->loadFile($filePath); |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
public function loadFile($filePath) |
| 116 |
{ |
| 117 |
require_once plugin_dir_path( __FILE__ ) . $filePath .'.php'; |
| 118 |
} |
| 119 |
|
| 120 |
public function addSettingsLinkFromPluginsPage($links) |
| 121 |
{ |
| 122 |
$settings_links = array( |
| 123 |
'<a href="' . admin_url( 'tools.php?page=logtivity' ) . '">Settings</a>', |
| 124 |
); |
| 125 |
|
| 126 |
return array_merge($settings_links, $links); |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
$logtivity = new Logtivity; |