Changeset 3219912
- Timestamp:
- 01/09/2025 11:32:10 PM (15 months ago)
- Location:
- logtivity
- Files:
-
- 4 added
- 10 edited
- 1 copied
-
tags/3.1.4 (copied) (copied from logtivity/trunk)
-
tags/3.1.4/Admin/Logtivity_Admin.php (modified) (1 diff)
-
tags/3.1.4/Admin/Logtivity_Dismiss_Notice_Controller.php (modified) (1 diff)
-
tags/3.1.4/Admin/Logtivity_Options.php (modified) (4 diffs)
-
tags/3.1.4/composer.json (added)
-
tags/3.1.4/composer.lock (added)
-
tags/3.1.4/logtivity.php (modified) (15 diffs)
-
tags/3.1.4/readme.txt (modified) (2 diffs)
-
trunk/Admin/Logtivity_Admin.php (modified) (1 diff)
-
trunk/Admin/Logtivity_Dismiss_Notice_Controller.php (modified) (1 diff)
-
trunk/Admin/Logtivity_Options.php (modified) (4 diffs)
-
trunk/composer.json (added)
-
trunk/composer.lock (added)
-
trunk/logtivity.php (modified) (15 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
logtivity/tags/3.1.4/Admin/Logtivity_Admin.php
r3160076 r3219912 23 23 */ 24 24 25 // phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols 26 // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace 27 // phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps 28 25 29 class Logtivity_Admin 26 30 { 27 protected $options; 28 29 protected static $shouldHidePluginFromUI = false; 30 31 public function __construct() 32 { 33 add_action( 'admin_menu', [$this, 'registerOptionsPage'] ); 34 35 add_action( 'wp_ajax_logtivity_update_settings', [$this, 'update']); 36 add_action( 'wp_ajax_nopriv_logtivity_update_settings', [$this, 'update']); 37 38 add_filter('logtivity_hide_from_menu', [$this, 'shouldHidePluginFromUI']); 39 add_filter('all_plugins', [$this, 'maybeHideFromMenu']); 40 41 $this->options = new Logtivity_Options; 42 } 43 44 public function maybeHideFromMenu($plugins) 45 { 46 if ($name = (new Logtivity_Options)->customPluginName()) { 47 if (isset($plugins['logtivity/logtivity.php'])) { 48 $plugins['logtivity/logtivity.php']['Name'] = $name; 49 } 50 } 51 52 if (!$this->shouldHidePluginFromUI(false)) { 53 return $plugins; 54 } 55 56 $shouldHide = ! array_key_exists( 'show_all', $_GET ); 57 58 if ( $shouldHide ) { 59 $hiddenPlugins = [ 60 'logtivity/logtivity.php', 61 ]; 62 63 foreach ( $hiddenPlugins as $hiddenPlugin ) { 64 unset( $plugins[ $hiddenPlugin ] ); 65 } 66 } 67 return $plugins; 68 } 69 70 public function shouldHidePluginFromUI($value) 71 { 72 if (self::$shouldHidePluginFromUI = (new Logtivity_Options)->isPluginHiddenFromUI()) { 73 return self::$shouldHidePluginFromUI; 74 } 75 return $value; 76 } 77 78 /** 79 * Register the settings page 80 */ 81 public function registerOptionsPage() 82 { 83 if (!apply_filters('logtivity_hide_from_menu', false)) { 84 add_menu_page( 85 ($this->options->isWhiteLabelMode() ? 'Logs' : 'Logtivity'), 86 ($this->options->isWhiteLabelMode() ? 'Logs' : 'Logtivity'), 87 'manage_options', 88 ($this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity'), 89 [$this, 'showLogIndexPage'], 90 'dashicons-chart-area', 91 26 92 ); 93 } 94 95 if (!apply_filters('logtivity_hide_settings_page', false)) { 96 add_submenu_page( 97 ($this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity'), 98 'Logtivity Settings', 99 'Settings', 100 'manage_options', 101 'logtivity'.'-settings', 102 [$this, 'showLogtivitySettingsPage'] 103 ); 104 } 105 } 106 107 /** 108 * Show the admin log index 109 * 110 * @return void 111 */ 112 public function showLogIndexPage() 113 { 114 if ( !current_user_can( 'manage_options' ) ) { 115 wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); 116 } 117 118 $options = $this->options->getOptions(); 119 120 echo logtivity_view('log-index', compact('options')); 121 } 122 123 /** 124 * Show the admin settings template 125 * 126 * @return void 127 */ 128 public function showLogtivitySettingsPage() 129 { 130 if ( !current_user_can( 'manage_options' ) ) { 131 wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); 132 } 133 134 $options = $this->options->getOptions(); 135 136 echo logtivity_view('settings', compact('options')); 137 } 138 139 /** 140 * Update the settings 141 * 142 * @return WP_Redirect 143 */ 144 public function update() 145 { 146 if (!wp_verify_nonce( $_POST['logtivity_update_settings'], 'logtivity_update_settings' )) 147 { 148 wp_safe_redirect( $this->settingsPageUrl() ); 149 exit; 150 return; 151 } 152 153 $user = new Logtivity_Wp_User; 154 155 if (!$user->hasRole('administrator')) { 156 wp_safe_redirect( $this->settingsPageUrl() ); 157 exit; 158 return; 159 } 160 161 $this->options->update([ 162 'logtivity_url_hash' => md5(home_url()), 163 ], 164 false 165 ); 166 167 delete_transient( 'dismissed-logtivity-site-url-has-changed-notice' ); 168 169 $this->options->update(); 170 171 (new Logtivity_Check_For_New_Settings)->checkForNewSettings(); 172 173 wp_safe_redirect( $this->settingsPageUrl() ); 174 exit; 175 } 176 177 /** 178 * Get the url to the settings page 179 * 180 * @return string 181 */ 182 public function settingsPageUrl() 183 { 184 return admin_url('admin.php?page=logtivity-settings'); 185 } 186 31 /** 32 * @var Logtivity_Options 33 */ 34 protected Logtivity_Options $options; 35 36 /** 37 * @var bool 38 */ 39 protected static bool $shouldHidePluginFromUI = false; 40 41 public function __construct() 42 { 43 add_action('admin_menu', [$this, 'registerOptionsPage']); 44 45 add_action('wp_ajax_logtivity_update_settings', [$this, 'update']); 46 add_action('wp_ajax_nopriv_logtivity_update_settings', [$this, 'update']); 47 48 add_filter('logtivity_hide_from_menu', [$this, 'shouldHidePluginFromUI']); 49 add_filter('all_plugins', [$this, 'maybeHideFromMenu']); 50 51 $this->options = new Logtivity_Options(); 52 } 53 54 /** 55 * @param array $plugins 56 * 57 * @return array 58 */ 59 public function maybeHideFromMenu(array $plugins): array 60 { 61 if ($name = (new Logtivity_Options())->customPluginName()) { 62 if (isset($plugins['logtivity/logtivity.php'])) { 63 $plugins['logtivity/logtivity.php']['Name'] = $name; 64 } 65 } 66 67 if (!$this->shouldHidePluginFromUI()) { 68 return $plugins; 69 } 70 71 $shouldHide = !array_key_exists('show_all', $_GET); 72 73 if ($shouldHide) { 74 $hiddenPlugins = [ 75 'logtivity/logtivity.php', 76 ]; 77 78 foreach ($hiddenPlugins as $hiddenPlugin) { 79 unset($plugins[$hiddenPlugin]); 80 } 81 } 82 return $plugins; 83 } 84 85 /** 86 * @param bool $value 87 * 88 * @return bool 89 */ 90 public function shouldHidePluginFromUI(bool $value = false): bool 91 { 92 if (static::$shouldHidePluginFromUI = (new Logtivity_Options())->isPluginHiddenFromUI()) { 93 return static::$shouldHidePluginFromUI; 94 } 95 96 return $value; 97 } 98 99 /** 100 * Register the settings page 101 */ 102 public function registerOptionsPage() 103 { 104 if (!apply_filters('logtivity_hide_from_menu', false)) { 105 add_menu_page( 106 ($this->options->isWhiteLabelMode() ? 'Logs' : 'Logtivity'), 107 ($this->options->isWhiteLabelMode() ? 'Logs' : 'Logtivity'), 108 'manage_options', 109 ($this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity'), 110 [$this, 'showLogIndexPage'], 111 'dashicons-chart-area', 112 26 113 ); 114 } 115 116 if (!apply_filters('logtivity_hide_settings_page', false)) { 117 add_submenu_page( 118 ($this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity'), 119 'Logtivity Settings', 120 'Settings', 121 'manage_options', 122 'logtivity' . '-settings', 123 [$this, 'showLogtivitySettingsPage'] 124 ); 125 } 126 } 127 128 /** 129 * Show the admin log index 130 * 131 * @return void 132 */ 133 public function showLogIndexPage() 134 { 135 if (!current_user_can('manage_options')) { 136 wp_die(__('You do not have sufficient permissions to access this page.')); 137 } 138 139 $options = $this->options->getOptions(); 140 141 echo logtivity_view('log-index', compact('options')); 142 } 143 144 /** 145 * Show the admin settings template 146 * 147 * @return void 148 */ 149 public function showLogtivitySettingsPage() 150 { 151 if (!current_user_can('manage_options')) { 152 wp_die(__('You do not have sufficient permissions to access this page.')); 153 } 154 155 $options = $this->options->getOptions(); 156 157 echo logtivity_view('settings', compact('options')); 158 } 159 160 /** 161 * Update the settings 162 * 163 * @return void 164 */ 165 public function update(): void 166 { 167 if (!wp_verify_nonce($_POST['logtivity_update_settings'], 'logtivity_update_settings')) { 168 wp_safe_redirect($this->settingsPageUrl()); 169 exit; 170 } 171 172 $user = new Logtivity_Wp_User(); 173 174 if (!$user->hasRole('administrator')) { 175 wp_safe_redirect($this->settingsPageUrl()); 176 exit; 177 } 178 179 $this->options->update( 180 [ 181 'logtivity_url_hash' => md5(home_url()), 182 ], 183 false 184 ); 185 186 delete_transient('dismissed-logtivity-site-url-has-changed-notice'); 187 188 $this->options->update(); 189 190 (new Logtivity_Check_For_New_Settings())->checkForNewSettings(); 191 192 wp_safe_redirect($this->settingsPageUrl()); 193 exit; 194 } 195 196 /** 197 * @return string 198 */ 199 public function settingsPageUrl(): string 200 { 201 return admin_url('admin.php?page=logtivity-settings'); 202 } 187 203 } 188 204 189 $Logtivity_Admin = new Logtivity_Admin; 190 205 new Logtivity_Admin(); -
logtivity/tags/3.1.4/Admin/Logtivity_Dismiss_Notice_Controller.php
r3160076 r3219912 23 23 */ 24 24 25 // phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols 26 // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace 27 // phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps 28 25 29 class Logtivity_Dismiss_Notice_Controller 26 30 { 27 protected $notices = [ 28 'logtivity-site-url-has-changed-notice' 29 ]; 31 /** 32 * @var string[] 33 */ 34 protected array $notices = [ 35 'logtivity-site-url-has-changed-notice', 36 ]; 30 37 31 public function __construct()32 {33 add_action("wp_ajax_nopriv_logtivity_dismiss_notice", [$this, 'dismiss']);34 add_action("wp_ajax_logtivity_dismiss_notice", [$this, 'dismiss']);35 }38 public function __construct() 39 { 40 add_action('wp_ajax_nopriv_logtivity_dismiss_notice', [$this, 'dismiss']); 41 add_action('wp_ajax_logtivity_dismiss_notice', [$this, 'dismiss']); 42 } 36 43 37 public function dismiss() 38 { 39 if ( !current_user_can( 'manage_options' ) ) { 40 wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); 41 } 44 /** 45 * @return void 46 */ 47 public function dismiss(): void 48 { 49 if (!current_user_can('manage_options')) { 50 wp_die(__('You do not have sufficient permissions to access this page.')); 51 } 42 52 43 if (!in_array($_POST['type'], $this->notices)) { 44 return; 45 } 53 $postType = sanitize_text_field($_POST['postType'] ?? null); 54 if (in_array($postType, $this->notices)) { 55 $dismissUntil = sanitize_text_field($_POST['dismissUntil'] ?? null); 46 56 47 if (isset($_POST['dismiss_until']) && $_POST['dismiss_until']) {48 set_transient(49 'dismissed-' . $_POST['type'],50 true, 51 (isset($_POST['dismiss_until']) ? intval($_POST['dismiss_until']) : 0) 52 );53 } else {54 update_option('dismissed-' . $_POST['type'], true);55 }57 if ($dismissUntil) { 58 set_transient( 59 'dismissed-' . $postType, 60 true, 61 (int)$dismissUntil 62 ); 63 } else { 64 update_option('dismissed-' . $postType, true); 65 } 56 66 57 wp_send_json(['message' => 'success']); 58 } 67 wp_send_json(['message' => 'success']); 68 } 69 } 59 70 } 60 71 61 new Logtivity_Dismiss_Notice_Controller ;72 new Logtivity_Dismiss_Notice_Controller(); -
logtivity/tags/3.1.4/Admin/Logtivity_Options.php
r3194447 r3219912 23 23 */ 24 24 25 // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace 26 // phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps 27 25 28 class Logtivity_Options 26 29 { … … 190 193 } 191 194 192 public function urlHash()193 {194 return $this->getOption('logtivity_url_hash');195 }196 197 195 /** 198 196 * @return string 199 197 */ 198 public function urlHash(): string 199 { 200 return (string)$this->getOption('logtivity_url_hash'); 201 } 202 203 /** 204 * @return string 205 */ 200 206 public function disabledLogs(): string 201 207 { … … 203 209 } 204 210 205 public function isWhiteLabelMode() 206 { 207 return $this->getOption('logtivity_enable_white_label_mode'); 208 } 209 210 public function isPluginHiddenFromUI() 211 { 212 return $this->getOption('logtivity_hide_plugin_from_ui'); 213 } 214 215 public function customPluginName() 216 { 217 return $this->getOption('logtivity_custom_plugin_name'); 211 /** 212 * @return bool 213 */ 214 public function isWhiteLabelMode(): bool 215 { 216 return (bool)$this->getOption('logtivity_enable_white_label_mode'); 217 } 218 219 /** 220 * @return bool 221 */ 222 public function isPluginHiddenFromUI(): bool 223 { 224 return (bool)$this->getOption('logtivity_hide_plugin_from_ui'); 225 } 226 227 /** 228 * @return string 229 */ 230 public function customPluginName(): string 231 { 232 return (string)$this->getOption('logtivity_custom_plugin_name'); 218 233 } 219 234 … … 283 298 protected function validateSetting(string $setting, $value): bool 284 299 { 285 $method = $this->rules[$setting] ?? null; 286 switch ($method) { 287 case 'is_bool': 288 $value = (bool)$value; 289 break; 290 291 default: 292 if (function_exists($method)) { 293 $value = $method($value); 294 295 } else { 296 $value = true; 297 } 298 break; 299 } 300 301 return $value; 300 if (isset($this->rules[$setting])) { 301 $method = $this->rules[$setting]; 302 303 if ($method == 'is_bool') { 304 return $method((bool)$value); 305 } 306 307 return $method($value); 308 } 309 310 return true; 302 311 } 303 312 } -
logtivity/tags/3.1.4/logtivity.php
r3194447 r3219912 5 5 * Plugin URI: https://logtivity.io 6 6 * Description: Record activity logs and errors logs across all your WordPress sites. 7 * Version: 3.1. 37 * Version: 3.1.4 8 8 * Author: Logtivity 9 9 * Text Domain: logtivity … … 31 31 * along with Logtivity. If not, see <https://www.gnu.org/licenses/>. 32 32 */ 33 34 // phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols 35 // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace 36 33 37 class Logtivity 34 38 { 35 protected $version = '3.1.3'; 39 /** 40 * @var string 41 */ 42 protected string $version = '3.1.4'; 36 43 37 44 /** 38 45 * List all classes here with their file paths. Keep class names the same as filenames. 39 46 * 40 * @var array41 */ 42 private $dependancies = [47 * @var string[] 48 */ 49 private array $dependencies = [ 43 50 'Helpers/Helpers', 44 51 'Helpers/Logtivity_Wp_User', … … 65 72 66 73 /** 67 * 68 * Log classes 69 * 70 */ 71 private $logClasses = [ 74 * @var string[] 75 */ 76 private array $logClasses = [ 72 77 /** 73 78 * Activity logging … … 84 89 85 90 /** 86 * List all integration depend ancies87 * 88 * @var array 89 */ 90 private $integrationDependancies = [91 * List all integration dependencies 92 * 93 * @var array[] 94 */ 95 private array $integrationDependencies = [ 91 96 'WP_DLM' => [ 92 97 'Logs/Download_Monitor/Logtivity_Download_Monitor', … … 119 124 public function __construct() 120 125 { 121 $this->loadDepend ancies();126 $this->loadDependencies(); 122 127 123 128 add_filter('plugin_action_links_' . plugin_basename(__FILE__), [$this, 'addSettingsLinkFromPluginsPage']); … … 136 141 } 137 142 138 public function loadDepend ancies()139 { 140 foreach ($this->depend ancies as $filePath) {143 public function loadDependencies() 144 { 145 foreach ($this->dependencies as $filePath) { 141 146 $this->loadFile($filePath); 142 147 } … … 149 154 $this->maybeLoadLogClasses(); 150 155 151 $this->loadIntegrationDepend ancies();156 $this->loadIntegrationDependencies(); 152 157 }); 153 158 } … … 163 168 * @return bool 164 169 */ 165 public function defaultLoggingDisabled() 166 { 167 return ( new Logtivity_Options)->getOption('logtivity_disable_default_logging');170 public function defaultLoggingDisabled(): bool 171 { 172 return (bool)(new Logtivity_Options())->getOption('logtivity_disable_default_logging'); 168 173 } 169 174 … … 175 180 } 176 181 177 public function loadIntegrationDepend ancies()178 { 179 foreach ($this->integrationDepend ancies as $key => $value) {182 public function loadIntegrationDependencies() 183 { 184 foreach ($this->integrationDependencies as $key => $value) { 180 185 if (class_exists($key)) { 181 186 foreach ($value as $filePath) { … … 191 196 } 192 197 193 public static function logError($error) 198 /** 199 * @param array $error 200 * 201 * @return Logtivity_Error_Logger 202 */ 203 public static function logError(array $error): Logtivity_Error_Logger 194 204 { 195 205 return new Logtivity_Error_Logger($error); 196 206 } 197 207 198 public function upgradeProcessComplete($upgrader_object, $options) 199 { 200 if ($options['type'] != 'plugin') { 201 return; 202 } 203 204 if ($options['action'] == 'update') { 205 return $this->setLogtivityToLoadFirst(); 206 } 207 } 208 209 public function setLogtivityToLoadFirst() 208 /** 209 * @param $upgraderObject 210 * @param $options 211 * 212 * @return null|void 213 */ 214 public function upgradeProcessComplete($upgraderObject, $options) 215 { 216 $type = $options['type'] ?? null; 217 $action = $options['action'] ?? null; 218 219 if ($type == 'plugin' && $action == 'update') { 220 $this->setLogtivityToLoadFirst(); 221 } 222 } 223 224 /** 225 * @return void 226 */ 227 public function setLogtivityToLoadFirst(): void 210 228 { 211 229 $path = str_replace(WP_PLUGIN_DIR . '/', '', __FILE__); … … 220 238 } 221 239 222 public function addSettingsLinkFromPluginsPage($links) 240 /** 241 * @param array $links 242 * 243 * @return string[] 244 */ 245 public function addSettingsLinkFromPluginsPage(array $links): array 223 246 { 224 247 if (apply_filters('logtivity_hide_settings_page', false)) { … … 226 249 } 227 250 228 $settings_links = [ 229 '<a href="' . admin_url('admin.php?page=logtivity-settings') . '">Settings</a>', 230 ]; 231 232 return array_merge($settings_links, $links); 233 } 234 235 public function activated() 251 return array_merge( 252 [ 253 sprintf('<a href="%s">Settings</a>', admin_url('admin.php?page=logtivity-settings')), 254 ], 255 $links 256 ); 257 } 258 259 /** 260 * @return void 261 */ 262 public function activated(): void 236 263 { 237 264 if (apply_filters('logtivity_hide_settings_page', false)) { … … 242 269 } 243 270 244 public function welcomeMessage() 271 /** 272 * @return void 273 */ 274 public function welcomeMessage(): void 245 275 { 246 276 if (get_transient('logtivity-welcome-notice')) { … … 251 281 } 252 282 253 public function checkForSiteUrlChange() 254 { 255 if (!current_user_can('manage_options')) { 256 return; 257 } 258 259 if (logtivity_has_site_url_changed() && !get_transient('dismissed-logtivity-site-url-has-changed-notice')) { 283 /** 284 * @return void 285 */ 286 public function checkForSiteUrlChange(): void 287 { 288 if ( 289 current_user_can('manage_options') 290 && logtivity_has_site_url_changed() 291 && !get_transient('dismissed-logtivity-site-url-has-changed-notice') 292 ) { 260 293 echo logtivity_view('site-url-changed-notice'); 261 294 } 262 295 } 263 296 264 public function loadScripts() 297 /** 298 * @return void 299 */ 300 public function loadScripts(): void 265 301 { 266 302 wp_enqueue_style( … … 285 321 } 286 322 287 $logtivity = new Logtivity ;323 $logtivity = new Logtivity(); -
logtivity/tags/3.1.4/readme.txt
r3194447 r3219912 5 5 Requires at least: 4.7 6 6 Tested up to: 6.6.2 7 Stable tag: 3.1. 37 Stable tag: 3.1.4 8 8 Requires PHP: 7.4 9 9 License: GPLv2 or later … … 262 262 263 263 == Changelog == 264 265 = 3.1.4 = 266 267 _Release Date - TBD 268 269 * Fix: Deprecation warning, #50 270 * Fix: Unable to uncheck settings 264 271 265 272 = 3.1.3 = -
logtivity/trunk/Admin/Logtivity_Admin.php
r3160076 r3219912 23 23 */ 24 24 25 // phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols 26 // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace 27 // phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps 28 25 29 class Logtivity_Admin 26 30 { 27 protected $options; 28 29 protected static $shouldHidePluginFromUI = false; 30 31 public function __construct() 32 { 33 add_action( 'admin_menu', [$this, 'registerOptionsPage'] ); 34 35 add_action( 'wp_ajax_logtivity_update_settings', [$this, 'update']); 36 add_action( 'wp_ajax_nopriv_logtivity_update_settings', [$this, 'update']); 37 38 add_filter('logtivity_hide_from_menu', [$this, 'shouldHidePluginFromUI']); 39 add_filter('all_plugins', [$this, 'maybeHideFromMenu']); 40 41 $this->options = new Logtivity_Options; 42 } 43 44 public function maybeHideFromMenu($plugins) 45 { 46 if ($name = (new Logtivity_Options)->customPluginName()) { 47 if (isset($plugins['logtivity/logtivity.php'])) { 48 $plugins['logtivity/logtivity.php']['Name'] = $name; 49 } 50 } 51 52 if (!$this->shouldHidePluginFromUI(false)) { 53 return $plugins; 54 } 55 56 $shouldHide = ! array_key_exists( 'show_all', $_GET ); 57 58 if ( $shouldHide ) { 59 $hiddenPlugins = [ 60 'logtivity/logtivity.php', 61 ]; 62 63 foreach ( $hiddenPlugins as $hiddenPlugin ) { 64 unset( $plugins[ $hiddenPlugin ] ); 65 } 66 } 67 return $plugins; 68 } 69 70 public function shouldHidePluginFromUI($value) 71 { 72 if (self::$shouldHidePluginFromUI = (new Logtivity_Options)->isPluginHiddenFromUI()) { 73 return self::$shouldHidePluginFromUI; 74 } 75 return $value; 76 } 77 78 /** 79 * Register the settings page 80 */ 81 public function registerOptionsPage() 82 { 83 if (!apply_filters('logtivity_hide_from_menu', false)) { 84 add_menu_page( 85 ($this->options->isWhiteLabelMode() ? 'Logs' : 'Logtivity'), 86 ($this->options->isWhiteLabelMode() ? 'Logs' : 'Logtivity'), 87 'manage_options', 88 ($this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity'), 89 [$this, 'showLogIndexPage'], 90 'dashicons-chart-area', 91 26 92 ); 93 } 94 95 if (!apply_filters('logtivity_hide_settings_page', false)) { 96 add_submenu_page( 97 ($this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity'), 98 'Logtivity Settings', 99 'Settings', 100 'manage_options', 101 'logtivity'.'-settings', 102 [$this, 'showLogtivitySettingsPage'] 103 ); 104 } 105 } 106 107 /** 108 * Show the admin log index 109 * 110 * @return void 111 */ 112 public function showLogIndexPage() 113 { 114 if ( !current_user_can( 'manage_options' ) ) { 115 wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); 116 } 117 118 $options = $this->options->getOptions(); 119 120 echo logtivity_view('log-index', compact('options')); 121 } 122 123 /** 124 * Show the admin settings template 125 * 126 * @return void 127 */ 128 public function showLogtivitySettingsPage() 129 { 130 if ( !current_user_can( 'manage_options' ) ) { 131 wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); 132 } 133 134 $options = $this->options->getOptions(); 135 136 echo logtivity_view('settings', compact('options')); 137 } 138 139 /** 140 * Update the settings 141 * 142 * @return WP_Redirect 143 */ 144 public function update() 145 { 146 if (!wp_verify_nonce( $_POST['logtivity_update_settings'], 'logtivity_update_settings' )) 147 { 148 wp_safe_redirect( $this->settingsPageUrl() ); 149 exit; 150 return; 151 } 152 153 $user = new Logtivity_Wp_User; 154 155 if (!$user->hasRole('administrator')) { 156 wp_safe_redirect( $this->settingsPageUrl() ); 157 exit; 158 return; 159 } 160 161 $this->options->update([ 162 'logtivity_url_hash' => md5(home_url()), 163 ], 164 false 165 ); 166 167 delete_transient( 'dismissed-logtivity-site-url-has-changed-notice' ); 168 169 $this->options->update(); 170 171 (new Logtivity_Check_For_New_Settings)->checkForNewSettings(); 172 173 wp_safe_redirect( $this->settingsPageUrl() ); 174 exit; 175 } 176 177 /** 178 * Get the url to the settings page 179 * 180 * @return string 181 */ 182 public function settingsPageUrl() 183 { 184 return admin_url('admin.php?page=logtivity-settings'); 185 } 186 31 /** 32 * @var Logtivity_Options 33 */ 34 protected Logtivity_Options $options; 35 36 /** 37 * @var bool 38 */ 39 protected static bool $shouldHidePluginFromUI = false; 40 41 public function __construct() 42 { 43 add_action('admin_menu', [$this, 'registerOptionsPage']); 44 45 add_action('wp_ajax_logtivity_update_settings', [$this, 'update']); 46 add_action('wp_ajax_nopriv_logtivity_update_settings', [$this, 'update']); 47 48 add_filter('logtivity_hide_from_menu', [$this, 'shouldHidePluginFromUI']); 49 add_filter('all_plugins', [$this, 'maybeHideFromMenu']); 50 51 $this->options = new Logtivity_Options(); 52 } 53 54 /** 55 * @param array $plugins 56 * 57 * @return array 58 */ 59 public function maybeHideFromMenu(array $plugins): array 60 { 61 if ($name = (new Logtivity_Options())->customPluginName()) { 62 if (isset($plugins['logtivity/logtivity.php'])) { 63 $plugins['logtivity/logtivity.php']['Name'] = $name; 64 } 65 } 66 67 if (!$this->shouldHidePluginFromUI()) { 68 return $plugins; 69 } 70 71 $shouldHide = !array_key_exists('show_all', $_GET); 72 73 if ($shouldHide) { 74 $hiddenPlugins = [ 75 'logtivity/logtivity.php', 76 ]; 77 78 foreach ($hiddenPlugins as $hiddenPlugin) { 79 unset($plugins[$hiddenPlugin]); 80 } 81 } 82 return $plugins; 83 } 84 85 /** 86 * @param bool $value 87 * 88 * @return bool 89 */ 90 public function shouldHidePluginFromUI(bool $value = false): bool 91 { 92 if (static::$shouldHidePluginFromUI = (new Logtivity_Options())->isPluginHiddenFromUI()) { 93 return static::$shouldHidePluginFromUI; 94 } 95 96 return $value; 97 } 98 99 /** 100 * Register the settings page 101 */ 102 public function registerOptionsPage() 103 { 104 if (!apply_filters('logtivity_hide_from_menu', false)) { 105 add_menu_page( 106 ($this->options->isWhiteLabelMode() ? 'Logs' : 'Logtivity'), 107 ($this->options->isWhiteLabelMode() ? 'Logs' : 'Logtivity'), 108 'manage_options', 109 ($this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity'), 110 [$this, 'showLogIndexPage'], 111 'dashicons-chart-area', 112 26 113 ); 114 } 115 116 if (!apply_filters('logtivity_hide_settings_page', false)) { 117 add_submenu_page( 118 ($this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity'), 119 'Logtivity Settings', 120 'Settings', 121 'manage_options', 122 'logtivity' . '-settings', 123 [$this, 'showLogtivitySettingsPage'] 124 ); 125 } 126 } 127 128 /** 129 * Show the admin log index 130 * 131 * @return void 132 */ 133 public function showLogIndexPage() 134 { 135 if (!current_user_can('manage_options')) { 136 wp_die(__('You do not have sufficient permissions to access this page.')); 137 } 138 139 $options = $this->options->getOptions(); 140 141 echo logtivity_view('log-index', compact('options')); 142 } 143 144 /** 145 * Show the admin settings template 146 * 147 * @return void 148 */ 149 public function showLogtivitySettingsPage() 150 { 151 if (!current_user_can('manage_options')) { 152 wp_die(__('You do not have sufficient permissions to access this page.')); 153 } 154 155 $options = $this->options->getOptions(); 156 157 echo logtivity_view('settings', compact('options')); 158 } 159 160 /** 161 * Update the settings 162 * 163 * @return void 164 */ 165 public function update(): void 166 { 167 if (!wp_verify_nonce($_POST['logtivity_update_settings'], 'logtivity_update_settings')) { 168 wp_safe_redirect($this->settingsPageUrl()); 169 exit; 170 } 171 172 $user = new Logtivity_Wp_User(); 173 174 if (!$user->hasRole('administrator')) { 175 wp_safe_redirect($this->settingsPageUrl()); 176 exit; 177 } 178 179 $this->options->update( 180 [ 181 'logtivity_url_hash' => md5(home_url()), 182 ], 183 false 184 ); 185 186 delete_transient('dismissed-logtivity-site-url-has-changed-notice'); 187 188 $this->options->update(); 189 190 (new Logtivity_Check_For_New_Settings())->checkForNewSettings(); 191 192 wp_safe_redirect($this->settingsPageUrl()); 193 exit; 194 } 195 196 /** 197 * @return string 198 */ 199 public function settingsPageUrl(): string 200 { 201 return admin_url('admin.php?page=logtivity-settings'); 202 } 187 203 } 188 204 189 $Logtivity_Admin = new Logtivity_Admin; 190 205 new Logtivity_Admin(); -
logtivity/trunk/Admin/Logtivity_Dismiss_Notice_Controller.php
r3160076 r3219912 23 23 */ 24 24 25 // phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols 26 // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace 27 // phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps 28 25 29 class Logtivity_Dismiss_Notice_Controller 26 30 { 27 protected $notices = [ 28 'logtivity-site-url-has-changed-notice' 29 ]; 31 /** 32 * @var string[] 33 */ 34 protected array $notices = [ 35 'logtivity-site-url-has-changed-notice', 36 ]; 30 37 31 public function __construct()32 {33 add_action("wp_ajax_nopriv_logtivity_dismiss_notice", [$this, 'dismiss']);34 add_action("wp_ajax_logtivity_dismiss_notice", [$this, 'dismiss']);35 }38 public function __construct() 39 { 40 add_action('wp_ajax_nopriv_logtivity_dismiss_notice', [$this, 'dismiss']); 41 add_action('wp_ajax_logtivity_dismiss_notice', [$this, 'dismiss']); 42 } 36 43 37 public function dismiss() 38 { 39 if ( !current_user_can( 'manage_options' ) ) { 40 wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); 41 } 44 /** 45 * @return void 46 */ 47 public function dismiss(): void 48 { 49 if (!current_user_can('manage_options')) { 50 wp_die(__('You do not have sufficient permissions to access this page.')); 51 } 42 52 43 if (!in_array($_POST['type'], $this->notices)) { 44 return; 45 } 53 $postType = sanitize_text_field($_POST['postType'] ?? null); 54 if (in_array($postType, $this->notices)) { 55 $dismissUntil = sanitize_text_field($_POST['dismissUntil'] ?? null); 46 56 47 if (isset($_POST['dismiss_until']) && $_POST['dismiss_until']) {48 set_transient(49 'dismissed-' . $_POST['type'],50 true, 51 (isset($_POST['dismiss_until']) ? intval($_POST['dismiss_until']) : 0) 52 );53 } else {54 update_option('dismissed-' . $_POST['type'], true);55 }57 if ($dismissUntil) { 58 set_transient( 59 'dismissed-' . $postType, 60 true, 61 (int)$dismissUntil 62 ); 63 } else { 64 update_option('dismissed-' . $postType, true); 65 } 56 66 57 wp_send_json(['message' => 'success']); 58 } 67 wp_send_json(['message' => 'success']); 68 } 69 } 59 70 } 60 71 61 new Logtivity_Dismiss_Notice_Controller ;72 new Logtivity_Dismiss_Notice_Controller(); -
logtivity/trunk/Admin/Logtivity_Options.php
r3194447 r3219912 23 23 */ 24 24 25 // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace 26 // phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps 27 25 28 class Logtivity_Options 26 29 { … … 190 193 } 191 194 192 public function urlHash()193 {194 return $this->getOption('logtivity_url_hash');195 }196 197 195 /** 198 196 * @return string 199 197 */ 198 public function urlHash(): string 199 { 200 return (string)$this->getOption('logtivity_url_hash'); 201 } 202 203 /** 204 * @return string 205 */ 200 206 public function disabledLogs(): string 201 207 { … … 203 209 } 204 210 205 public function isWhiteLabelMode() 206 { 207 return $this->getOption('logtivity_enable_white_label_mode'); 208 } 209 210 public function isPluginHiddenFromUI() 211 { 212 return $this->getOption('logtivity_hide_plugin_from_ui'); 213 } 214 215 public function customPluginName() 216 { 217 return $this->getOption('logtivity_custom_plugin_name'); 211 /** 212 * @return bool 213 */ 214 public function isWhiteLabelMode(): bool 215 { 216 return (bool)$this->getOption('logtivity_enable_white_label_mode'); 217 } 218 219 /** 220 * @return bool 221 */ 222 public function isPluginHiddenFromUI(): bool 223 { 224 return (bool)$this->getOption('logtivity_hide_plugin_from_ui'); 225 } 226 227 /** 228 * @return string 229 */ 230 public function customPluginName(): string 231 { 232 return (string)$this->getOption('logtivity_custom_plugin_name'); 218 233 } 219 234 … … 283 298 protected function validateSetting(string $setting, $value): bool 284 299 { 285 $method = $this->rules[$setting] ?? null; 286 switch ($method) { 287 case 'is_bool': 288 $value = (bool)$value; 289 break; 290 291 default: 292 if (function_exists($method)) { 293 $value = $method($value); 294 295 } else { 296 $value = true; 297 } 298 break; 299 } 300 301 return $value; 300 if (isset($this->rules[$setting])) { 301 $method = $this->rules[$setting]; 302 303 if ($method == 'is_bool') { 304 return $method((bool)$value); 305 } 306 307 return $method($value); 308 } 309 310 return true; 302 311 } 303 312 } -
logtivity/trunk/logtivity.php
r3194447 r3219912 5 5 * Plugin URI: https://logtivity.io 6 6 * Description: Record activity logs and errors logs across all your WordPress sites. 7 * Version: 3.1. 37 * Version: 3.1.4 8 8 * Author: Logtivity 9 9 * Text Domain: logtivity … … 31 31 * along with Logtivity. If not, see <https://www.gnu.org/licenses/>. 32 32 */ 33 34 // phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols 35 // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace 36 33 37 class Logtivity 34 38 { 35 protected $version = '3.1.3'; 39 /** 40 * @var string 41 */ 42 protected string $version = '3.1.4'; 36 43 37 44 /** 38 45 * List all classes here with their file paths. Keep class names the same as filenames. 39 46 * 40 * @var array41 */ 42 private $dependancies = [47 * @var string[] 48 */ 49 private array $dependencies = [ 43 50 'Helpers/Helpers', 44 51 'Helpers/Logtivity_Wp_User', … … 65 72 66 73 /** 67 * 68 * Log classes 69 * 70 */ 71 private $logClasses = [ 74 * @var string[] 75 */ 76 private array $logClasses = [ 72 77 /** 73 78 * Activity logging … … 84 89 85 90 /** 86 * List all integration depend ancies87 * 88 * @var array 89 */ 90 private $integrationDependancies = [91 * List all integration dependencies 92 * 93 * @var array[] 94 */ 95 private array $integrationDependencies = [ 91 96 'WP_DLM' => [ 92 97 'Logs/Download_Monitor/Logtivity_Download_Monitor', … … 119 124 public function __construct() 120 125 { 121 $this->loadDepend ancies();126 $this->loadDependencies(); 122 127 123 128 add_filter('plugin_action_links_' . plugin_basename(__FILE__), [$this, 'addSettingsLinkFromPluginsPage']); … … 136 141 } 137 142 138 public function loadDepend ancies()139 { 140 foreach ($this->depend ancies as $filePath) {143 public function loadDependencies() 144 { 145 foreach ($this->dependencies as $filePath) { 141 146 $this->loadFile($filePath); 142 147 } … … 149 154 $this->maybeLoadLogClasses(); 150 155 151 $this->loadIntegrationDepend ancies();156 $this->loadIntegrationDependencies(); 152 157 }); 153 158 } … … 163 168 * @return bool 164 169 */ 165 public function defaultLoggingDisabled() 166 { 167 return ( new Logtivity_Options)->getOption('logtivity_disable_default_logging');170 public function defaultLoggingDisabled(): bool 171 { 172 return (bool)(new Logtivity_Options())->getOption('logtivity_disable_default_logging'); 168 173 } 169 174 … … 175 180 } 176 181 177 public function loadIntegrationDepend ancies()178 { 179 foreach ($this->integrationDepend ancies as $key => $value) {182 public function loadIntegrationDependencies() 183 { 184 foreach ($this->integrationDependencies as $key => $value) { 180 185 if (class_exists($key)) { 181 186 foreach ($value as $filePath) { … … 191 196 } 192 197 193 public static function logError($error) 198 /** 199 * @param array $error 200 * 201 * @return Logtivity_Error_Logger 202 */ 203 public static function logError(array $error): Logtivity_Error_Logger 194 204 { 195 205 return new Logtivity_Error_Logger($error); 196 206 } 197 207 198 public function upgradeProcessComplete($upgrader_object, $options) 199 { 200 if ($options['type'] != 'plugin') { 201 return; 202 } 203 204 if ($options['action'] == 'update') { 205 return $this->setLogtivityToLoadFirst(); 206 } 207 } 208 209 public function setLogtivityToLoadFirst() 208 /** 209 * @param $upgraderObject 210 * @param $options 211 * 212 * @return null|void 213 */ 214 public function upgradeProcessComplete($upgraderObject, $options) 215 { 216 $type = $options['type'] ?? null; 217 $action = $options['action'] ?? null; 218 219 if ($type == 'plugin' && $action == 'update') { 220 $this->setLogtivityToLoadFirst(); 221 } 222 } 223 224 /** 225 * @return void 226 */ 227 public function setLogtivityToLoadFirst(): void 210 228 { 211 229 $path = str_replace(WP_PLUGIN_DIR . '/', '', __FILE__); … … 220 238 } 221 239 222 public function addSettingsLinkFromPluginsPage($links) 240 /** 241 * @param array $links 242 * 243 * @return string[] 244 */ 245 public function addSettingsLinkFromPluginsPage(array $links): array 223 246 { 224 247 if (apply_filters('logtivity_hide_settings_page', false)) { … … 226 249 } 227 250 228 $settings_links = [ 229 '<a href="' . admin_url('admin.php?page=logtivity-settings') . '">Settings</a>', 230 ]; 231 232 return array_merge($settings_links, $links); 233 } 234 235 public function activated() 251 return array_merge( 252 [ 253 sprintf('<a href="%s">Settings</a>', admin_url('admin.php?page=logtivity-settings')), 254 ], 255 $links 256 ); 257 } 258 259 /** 260 * @return void 261 */ 262 public function activated(): void 236 263 { 237 264 if (apply_filters('logtivity_hide_settings_page', false)) { … … 242 269 } 243 270 244 public function welcomeMessage() 271 /** 272 * @return void 273 */ 274 public function welcomeMessage(): void 245 275 { 246 276 if (get_transient('logtivity-welcome-notice')) { … … 251 281 } 252 282 253 public function checkForSiteUrlChange() 254 { 255 if (!current_user_can('manage_options')) { 256 return; 257 } 258 259 if (logtivity_has_site_url_changed() && !get_transient('dismissed-logtivity-site-url-has-changed-notice')) { 283 /** 284 * @return void 285 */ 286 public function checkForSiteUrlChange(): void 287 { 288 if ( 289 current_user_can('manage_options') 290 && logtivity_has_site_url_changed() 291 && !get_transient('dismissed-logtivity-site-url-has-changed-notice') 292 ) { 260 293 echo logtivity_view('site-url-changed-notice'); 261 294 } 262 295 } 263 296 264 public function loadScripts() 297 /** 298 * @return void 299 */ 300 public function loadScripts(): void 265 301 { 266 302 wp_enqueue_style( … … 285 321 } 286 322 287 $logtivity = new Logtivity ;323 $logtivity = new Logtivity(); -
logtivity/trunk/readme.txt
r3194447 r3219912 5 5 Requires at least: 4.7 6 6 Tested up to: 6.6.2 7 Stable tag: 3.1. 37 Stable tag: 3.1.4 8 8 Requires PHP: 7.4 9 9 License: GPLv2 or later … … 262 262 263 263 == Changelog == 264 265 = 3.1.4 = 266 267 _Release Date - TBD 268 269 * Fix: Deprecation warning, #50 270 * Fix: Unable to uncheck settings 264 271 265 272 = 3.1.3 =
Note: See TracChangeset
for help on using the changeset viewer.