| 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.11.0 |
| 8 |
* Author: Logtivity |
| 9 |
* Text Domain: logtivity |
| 10 |
*/ |
| 11 |
|
| 12 |
class Logtivity |
| 13 |
{ |
| 14 |
protected $version = '1.11.0'; |
| 15 |
|
| 16 |
/** |
| 17 |
* List all classes here with their file paths. Keep class names the same as filenames. |
| 18 |
* |
| 19 |
* @var array |
| 20 |
*/ |
| 21 |
private $dependancies = [ |
| 22 |
'Helpers/Helpers', |
| 23 |
'Helpers/Logtivity_Wp_User', |
| 24 |
'Admin/Logtivity_Log_Index_Controller', |
| 25 |
'Admin/Logtivity_Dismiss_Notice_Controller', |
| 26 |
'Admin/Logtivity_Options', |
| 27 |
'Admin/Logtivity_Admin', |
| 28 |
'Services/Logtivity_Api', |
| 29 |
'Services/Logtivity_Logger', |
| 30 |
'Services/Logtivity_Register_Site', |
| 31 |
'Helpers/Logtivity_Log_Global_Function', |
| 32 |
'Logs/Logtivity_Abstract_Logger', |
| 33 |
]; |
| 34 |
|
| 35 |
/** |
| 36 |
* |
| 37 |
* Log classes |
| 38 |
* |
| 39 |
*/ |
| 40 |
private $logClasses = [ |
| 41 |
'Logs/Core/Logtivity_Post', |
| 42 |
'Logs/Core/Logtivity_User', |
| 43 |
'Logs/Core/Logtivity_Core', |
| 44 |
'Logs/Core/Logtivity_Theme', |
| 45 |
'Logs/Core/Logtivity_Plugin', |
| 46 |
'Logs/Core/Logtivity_Comment', |
| 47 |
]; |
| 48 |
|
| 49 |
/** |
| 50 |
* List all integration dependancies |
| 51 |
* |
| 52 |
* @var array |
| 53 |
*/ |
| 54 |
private $integrationDependancies = [ |
| 55 |
'WP_DLM' => [ |
| 56 |
'Logs/Download_Monitor/Logtivity_Download_Monitor', |
| 57 |
], |
| 58 |
'MeprCtrlFactory' => [ |
| 59 |
'Logs/Memberpress/Logtivity_Memberpress', |
| 60 |
], |
| 61 |
'Easy_Digital_Downloads' => [ |
| 62 |
'Logs/Easy_Digital_Downloads/Logtivity_Abstract_Easy_Digital_Downloads', |
| 63 |
'Logs/Easy_Digital_Downloads/Logtivity_Easy_Digital_Downloads' |
| 64 |
], |
| 65 |
'EDD_Software_Licensing' => [ |
| 66 |
'Logs/Easy_Digital_Downloads/Logtivity_Easy_Digital_Downloads_Software_Licensing' |
| 67 |
], |
| 68 |
'EDD_Recurring' => [ |
| 69 |
'Logs/Easy_Digital_Downloads/Logtivity_Easy_Digital_Downloads_Recurring' |
| 70 |
], |
| 71 |
'FrmHooksController' => [ |
| 72 |
'Logs/Formidable/Logtivity_FrmEntryFormatter', |
| 73 |
'Logs/Formidable/Logtivity_Formidable' |
| 74 |
] |
| 75 |
]; |
| 76 |
|
| 77 |
public function __construct() |
| 78 |
{ |
| 79 |
$this->loadDependancies(); |
| 80 |
|
| 81 |
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), [$this, 'addSettingsLinkFromPluginsPage'] ); |
| 82 |
|
| 83 |
register_activation_hook( __FILE__, [$this, 'activated']); |
| 84 |
|
| 85 |
add_action( 'admin_notices', [$this, 'welcomeMessage']); |
| 86 |
|
| 87 |
add_action( 'admin_notices', [$this, 'checkForSiteUrlChange']); |
| 88 |
|
| 89 |
add_action('admin_enqueue_scripts', [$this, 'loadScripts']); |
| 90 |
} |
| 91 |
|
| 92 |
public static function log($action = null, $meta = null, $user_id = null) |
| 93 |
{ |
| 94 |
return Logtivity_Logger::log($action, $meta, $user_id); |
| 95 |
} |
| 96 |
|
| 97 |
public function loadDependancies() |
| 98 |
{ |
| 99 |
foreach ($this->dependancies as $filePath) |
| 100 |
{ |
| 101 |
$this->loadFile($filePath); |
| 102 |
} |
| 103 |
|
| 104 |
$this->maybeLoadLogClasses(); |
| 105 |
|
| 106 |
$this->loadIntegrationDependancies(); |
| 107 |
} |
| 108 |
|
| 109 |
public function maybeLoadLogClasses() |
| 110 |
{ |
| 111 |
if ($this->defaultLoggingDisabled()) { |
| 112 |
return; |
| 113 |
} |
| 114 |
|
| 115 |
foreach ($this->logClasses as $filePath) |
| 116 |
{ |
| 117 |
$this->loadFile($filePath); |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Is the default Event logging from within the plugin enabled |
| 123 |
* |
| 124 |
* @return bool |
| 125 |
*/ |
| 126 |
public function defaultLoggingDisabled() |
| 127 |
{ |
| 128 |
return (new Logtivity_Options)->getOption('logtivity_disable_default_logging'); |
| 129 |
} |
| 130 |
|
| 131 |
public function loadIntegrationDependancies() |
| 132 |
{ |
| 133 |
add_action('plugins_loaded', function() { |
| 134 |
foreach ($this->integrationDependancies as $key => $value) |
| 135 |
{ |
| 136 |
if (class_exists($key)) { |
| 137 |
foreach ($value as $filePath) |
| 138 |
{ |
| 139 |
$this->loadFile($filePath); |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
}); |
| 144 |
} |
| 145 |
|
| 146 |
public function loadFile($filePath) |
| 147 |
{ |
| 148 |
require_once plugin_dir_path( __FILE__ ) . $filePath .'.php'; |
| 149 |
} |
| 150 |
|
| 151 |
public function addSettingsLinkFromPluginsPage($links) |
| 152 |
{ |
| 153 |
if (apply_filters('logtivity_hide_settings_page', false)) { |
| 154 |
return $links; |
| 155 |
} |
| 156 |
|
| 157 |
$settings_links = array( |
| 158 |
'<a href="' . admin_url( 'admin.php?page=logtivity-settings' ) . '">Settings</a>', |
| 159 |
); |
| 160 |
|
| 161 |
return array_merge($settings_links, $links); |
| 162 |
} |
| 163 |
|
| 164 |
public function activated() |
| 165 |
{ |
| 166 |
if (apply_filters('logtivity_hide_settings_page', false)) { |
| 167 |
return; |
| 168 |
} |
| 169 |
|
| 170 |
set_transient( 'logtivity-welcome-notice', true, 5 ); |
| 171 |
} |
| 172 |
|
| 173 |
public function welcomeMessage() |
| 174 |
{ |
| 175 |
if(get_transient( 'logtivity-welcome-notice') ) { |
| 176 |
echo logtivity_view('activation'); |
| 177 |
|
| 178 |
delete_transient( 'logtivity-welcome-notice' ); |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
public function checkForSiteUrlChange() |
| 183 |
{ |
| 184 |
if ( !current_user_can( 'manage_options' ) ) { |
| 185 |
return; |
| 186 |
} |
| 187 |
|
| 188 |
if(logtivity_has_site_url_changed() && !get_transient( 'dismissed-logtivity-site-url-has-changed-notice')) { |
| 189 |
echo logtivity_view('site-url-changed-notice'); |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
public function loadScripts() |
| 194 |
{ |
| 195 |
wp_enqueue_style( 'logtivity_admin_css', plugin_dir_url(__FILE__) . 'assets/admin.css', false, $this->version ); |
| 196 |
wp_enqueue_script( 'logtivity_admin_js', plugin_dir_url(__FILE__) . 'assets/app.js', false, $this->version ); |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
$logtivity = new Logtivity; |