Changeset 2805342
- Timestamp:
- 10/26/2022 08:38:31 PM (3 years ago)
- Location:
- logtivity
- Files:
-
- 72 added
- 10 edited
-
tags/2.0 (added)
-
tags/2.0/.gitignore (added)
-
tags/2.0/Admin (added)
-
tags/2.0/Admin/Logtivity_Admin.php (added)
-
tags/2.0/Admin/Logtivity_Dismiss_Notice_Controller.php (added)
-
tags/2.0/Admin/Logtivity_Log_Index_Controller.php (added)
-
tags/2.0/Admin/Logtivity_Options.php (added)
-
tags/2.0/Errors (added)
-
tags/2.0/Errors/Logtivity_Error_Log.php (added)
-
tags/2.0/Errors/Logtivity_Error_Logger.php (added)
-
tags/2.0/Errors/Logtivity_Stack_Trace.php (added)
-
tags/2.0/Errors/Logtivity_Stack_Trace_Snippet.php (added)
-
tags/2.0/Helpers (added)
-
tags/2.0/Helpers/Helpers.php (added)
-
tags/2.0/Helpers/Logtivity_Log_Global_Function.php (added)
-
tags/2.0/Helpers/Logtivity_Wp_User.php (added)
-
tags/2.0/Logs (added)
-
tags/2.0/Logs/Code_Snippets (added)
-
tags/2.0/Logs/Code_Snippets/Logtivity_Code_Snippets.php (added)
-
tags/2.0/Logs/Core (added)
-
tags/2.0/Logs/Core/Logtivity_Comment.php (added)
-
tags/2.0/Logs/Core/Logtivity_Core.php (added)
-
tags/2.0/Logs/Core/Logtivity_Meta.php (added)
-
tags/2.0/Logs/Core/Logtivity_Plugin.php (added)
-
tags/2.0/Logs/Core/Logtivity_Post.php (added)
-
tags/2.0/Logs/Core/Logtivity_Term.php (added)
-
tags/2.0/Logs/Core/Logtivity_Theme.php (added)
-
tags/2.0/Logs/Core/Logtivity_User.php (added)
-
tags/2.0/Logs/Download_Monitor (added)
-
tags/2.0/Logs/Download_Monitor/Logtivity_Download_Monitor.php (added)
-
tags/2.0/Logs/Easy_Digital_Downloads (added)
-
tags/2.0/Logs/Easy_Digital_Downloads/Logtivity_Abstract_Easy_Digital_Downloads.php (added)
-
tags/2.0/Logs/Easy_Digital_Downloads/Logtivity_Easy_Digital_Downloads.php (added)
-
tags/2.0/Logs/Easy_Digital_Downloads/Logtivity_Easy_Digital_Downloads_Recurring.php (added)
-
tags/2.0/Logs/Easy_Digital_Downloads/Logtivity_Easy_Digital_Downloads_Software_Licensing.php (added)
-
tags/2.0/Logs/Formidable (added)
-
tags/2.0/Logs/Formidable/Logtivity_Formidable.php (added)
-
tags/2.0/Logs/Formidable/Logtivity_FrmEntryFormatter.php (added)
-
tags/2.0/Logs/Logtivity_Abstract_Logger.php (added)
-
tags/2.0/Logs/Memberpress (added)
-
tags/2.0/Logs/Memberpress/Logtivity_Memberpress.php (added)
-
tags/2.0/Logs/WP_All_Import (added)
-
tags/2.0/Logs/WP_All_Import/Logtivity_WP_All_Import.php (added)
-
tags/2.0/Services (added)
-
tags/2.0/Services/Logtivity_Api.php (added)
-
tags/2.0/Services/Logtivity_Check_For_Disabled_Individual_Logs.php (added)
-
tags/2.0/Services/Logtivity_Logger.php (added)
-
tags/2.0/Services/Logtivity_Register_Site.php (added)
-
tags/2.0/Services/Logtivity_User_Logger_Trait.php (added)
-
tags/2.0/assets (added)
-
tags/2.0/assets/admin.css (added)
-
tags/2.0/assets/app.js (added)
-
tags/2.0/assets/logtivity-logo.svg (added)
-
tags/2.0/logtivity.php (added)
-
tags/2.0/readme.md (added)
-
tags/2.0/readme.txt (added)
-
tags/2.0/views (added)
-
tags/2.0/views/_admin-footer.php (added)
-
tags/2.0/views/_admin-header.php (added)
-
tags/2.0/views/_admin-sidebar.php (added)
-
tags/2.0/views/_log-show.php (added)
-
tags/2.0/views/_logs-loop.php (added)
-
tags/2.0/views/activation.php (added)
-
tags/2.0/views/log-index.php (added)
-
tags/2.0/views/settings.php (added)
-
tags/2.0/views/site-url-changed-notice.php (added)
-
trunk/Admin/Logtivity_Options.php (modified) (2 diffs)
-
trunk/Errors (added)
-
trunk/Errors/Logtivity_Error_Log.php (added)
-
trunk/Errors/Logtivity_Error_Logger.php (added)
-
trunk/Errors/Logtivity_Stack_Trace.php (added)
-
trunk/Errors/Logtivity_Stack_Trace_Snippet.php (added)
-
trunk/Helpers/Helpers.php (modified) (1 diff)
-
trunk/Helpers/Logtivity_Wp_User.php (modified) (15 diffs)
-
trunk/Logs/Core/Logtivity_Core.php (modified) (4 diffs)
-
trunk/Services/Logtivity_Api.php (modified) (4 diffs)
-
trunk/Services/Logtivity_Logger.php (modified) (6 diffs)
-
trunk/Services/Logtivity_User_Logger_Trait.php (added)
-
trunk/logtivity.php (modified) (8 diffs)
-
trunk/readme.md (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/views/settings.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
logtivity/trunk/Admin/Logtivity_Options.php
r2744100 r2805342 22 22 'logtivity_global_disabled_logs', 23 23 'logtivity_enable_white_label_mode', 24 'logtivity_disable_error_logging', 25 'logtivity_disabled_error_levels', 24 26 ]; 25 27 … … 124 126 { 125 127 return $this->getOption('logtivity_should_log_username'); 128 } 129 130 /** 131 * Get the error levels that are disabled 132 * 133 * @return array 134 */ 135 public function disabledErrorLevels() 136 { 137 $result = $this->getOption('logtivity_disabled_error_levels'); 138 139 if (is_array($result)) { 140 return array_keys(array_filter($result)); 141 } 142 143 return []; 126 144 } 127 145 -
logtivity/trunk/Helpers/Helpers.php
r2682104 r2805342 81 81 return $hash !== md5(home_url()); 82 82 } 83 84 function logtivity_get_error_levels() 85 { 86 return [ 87 E_ALL => 'E_ALL', 88 E_USER_DEPRECATED => 'E_USER_DEPRECATED', 89 E_DEPRECATED => 'E_DEPRECATED', 90 E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR', 91 E_STRICT => 'E_STRICT', 92 E_USER_NOTICE => 'E_USER_NOTICE', 93 E_USER_WARNING => 'E_USER_WARNING', 94 E_USER_ERROR => 'E_USER_ERROR', 95 E_COMPILE_WARNING => 'E_COMPILE_WARNING', 96 E_COMPILE_ERROR => 'E_COMPILE_ERROR', 97 E_CORE_WARNING => 'E_CORE_WARNING', 98 E_CORE_ERROR => 'E_CORE_ERROR', 99 E_NOTICE => 'E_NOTICE', 100 E_PARSE => 'E_PARSE', 101 E_WARNING => 'E_WARNING', 102 E_ERROR => 'E_ERROR', 103 ]; 104 } -
logtivity/trunk/Helpers/Logtivity_Wp_User.php
r2737295 r2805342 7 7 public function __construct($user = null, $field = 'ID') 8 8 { 9 if (is_null($user)) 10 { 11 $this->user = wp_get_current_user(); 12 } 13 elseif ($user instanceof WP_User) 14 { 9 if (is_null($user)) { 10 if (function_exists('wp_get_current_user')) { 11 $this->user = wp_get_current_user(); 12 } 13 } elseif ($user instanceof WP_User) { 15 14 $this->user = $user; 16 } 17 else18 {19 $this->user = get_user_by($field, $user);15 } else { 16 if (function_exists('get_user_by')) { 17 $this->user = get_user_by($field, $user); 18 } 20 19 } 21 20 } … … 42 41 public function id() 43 42 { 43 if (!$this->user) { 44 return; 45 } 46 44 47 if ($this->user->ID == 0) { 45 48 return; … … 51 54 public function userLogin() 52 55 { 56 if (!$this->user) { 57 return; 58 } 59 53 60 if ($this->user->ID == 0) { 54 61 return; … … 60 67 public function email() 61 68 { 69 if (!$this->user) { 70 return; 71 } 72 62 73 return $this->user->user_email; 63 74 } … … 65 76 public function name() 66 77 { 78 if (!$this->user) { 79 return; 80 } 81 67 82 return $this->firstName() . ' ' . $this->lastName(); 68 83 } … … 70 85 public function firstName() 71 86 { 87 if (!$this->user) { 88 return; 89 } 90 72 91 return $this->meta('first_name'); 73 92 } … … 75 94 public function lastName() 76 95 { 96 if (!$this->user) { 97 return; 98 } 99 77 100 return $this->meta('last_name'); 78 101 } … … 80 103 public function displayName() 81 104 { 105 if (!$this->user) { 106 return; 107 } 108 82 109 return $this->user->display_name; 83 110 } … … 85 112 public function niceName() 86 113 { 114 if (!$this->user) { 115 return; 116 } 117 87 118 return $this->user->user_nicename; 88 119 } … … 90 121 public function profileLink() 91 122 { 123 if (!$this->user) { 124 return; 125 } 126 92 127 return add_query_arg( 'user_id', $this->id(), self_admin_url( 'user-edit.php' ) ); 93 128 } … … 102 137 public function meta($meta_key, $returnString = true) 103 138 { 139 if (!$this->user) { 140 return; 141 } 142 104 143 $meta = get_user_meta($this->user->ID, $meta_key, $returnString); 105 144 … … 128 167 public function isLoggedIn() 129 168 { 169 if (!$this->user) { 170 return; 171 } 172 130 173 if ($this->user->ID == 0) { 131 174 return false; … … 144 187 public function hasRole($role) 145 188 { 189 if (!$this->user) { 190 return; 191 } 192 146 193 if ( in_array($role, $this->getRoles()) ) { 147 194 return true; … … 158 205 public function getRoles() 159 206 { 207 if (!$this->user) { 208 return; 209 } 210 160 211 return $this->user->roles; 161 212 } … … 168 219 public function getRole() 169 220 { 221 if (!$this->user) { 222 return; 223 } 224 170 225 foreach ($this->getRoles() as $role) { 171 226 return $role; -
logtivity/trunk/Logs/Core/Logtivity_Core.php
r2744371 r2805342 80 80 public function optionUpdated($option, $old_value, $value) 81 81 { 82 if ($this->getRequestMethod() == 'GET') { 83 return; 84 } 85 82 86 if (!is_admin() || $old_value == $value) { 83 87 return; … … 93 97 'logtivity_global_disabled_logs', 94 98 'logtivity_enable_white_label_mode', 99 'logtivity_disabled_error_levels', 100 'logtivity_disable_error_logging', 95 101 'recently_activated', 96 102 'active_plugins', 97 103 'jp_sync_last_success_sync', 104 'jp_sync_retry_after_sync', 105 'postman_state', 98 106 'jetpack_sync_settings_dedicated_sync_enabled', 99 107 'jetpack_plugin_api_action_links', … … 119 127 '_edd_table_check', 120 128 'woocommerce_marketplace_suggestions', 129 'recently_edited', 130 'rewrite_rules', 131 'limit_login_retries', 132 'post_views_count', 121 133 ]; 122 134 … … 149 161 } 150 162 163 private function getRequestMethod() 164 { 165 return $_SERVER['REQUEST_METHOD'] ?? null; 166 } 167 151 168 public function permalinksUpdated($old_permalink_structure, $permalink_structure) 152 169 { -
logtivity/trunk/Services/Logtivity_Api.php
r2723235 r2805342 16 16 */ 17 17 public $waitForResponse = true; 18 19 /** 20 * Definitely don't wait for a response. 21 * 22 * @var boolean 23 */ 24 public $asyncOverride = false; 18 25 19 26 /** … … 56 63 } 57 64 65 public function async() 66 { 67 $this->asyncOverride = true; 68 69 return $this; 70 } 71 58 72 /** 59 73 * Make a request to the Logtivity API … … 82 96 } 83 97 84 $shouldLogLatestResponse = $this->waitForResponse || $this->options->shouldLogLatestResponse();98 $shouldLogLatestResponse = !$this->asyncOverride && ($this->waitForResponse || $this->options->shouldLogLatestResponse()); 85 99 86 100 $response = wp_remote_post($this->getEndpoint($url), [ … … 116 130 'logtivity_global_disabled_logs' => $body['settings']['disabled_logs'], 117 131 'logtivity_enable_white_label_mode' => $body['settings']['enable_white_label_mode'], 132 'logtivity_disabled_error_levels' => $body['settings']['disabled_error_levels'], 133 'logtivity_disable_error_logging' => $body['settings']['disable_error_logging'], 118 134 ], 119 135 false -
logtivity/trunk/Services/Logtivity_Logger.php
r2707715 r2805342 3 3 class Logtivity_Logger extends Logtivity_Api 4 4 { 5 use Logtivity_User_Logger_Trait; 6 5 7 /** 6 8 * Can this instance log something … … 9 11 */ 10 12 public $active = true; 11 12 /**13 * Logtivity_Wp_User14 *15 * @var object16 */17 public $user;18 13 19 14 /** … … 106 101 107 102 /** 108 * Set the user for the current log instance109 *110 * @param integer $user_id111 */112 public function setUser($user_id)113 {114 $this->user = new Logtivity_Wp_User($user_id);115 116 return $this;117 }118 119 /**120 103 * Set the action string before sending 121 104 * … … 189 172 * @param mixed $value 190 173 */ 191 public function addMetaIf($condition = false, $key, $value)174 public function addMetaIf($condition, $key, $value) 192 175 { 193 176 if ($condition) { … … 275 258 276 259 /** 277 * Protected function to get the User ID if the user is logged in278 *279 * @return mixed string|integer280 */281 protected function getUserID()282 {283 if (!$this->options->shouldStoreUserId()) {284 return;285 }286 287 if (!$this->user->isLoggedIn()) {288 return;289 }290 291 return $this->user->id();292 }293 294 /**295 * Maybe get the users IP address296 *297 * @return string|false298 */299 protected function maybeGetUsersIp()300 {301 if (!$this->options->shouldStoreIp()) {302 return;303 }304 305 if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {306 307 //check ip from share internet308 return $_SERVER['HTTP_CLIENT_IP'];309 310 } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {311 312 //to check ip is pass from proxy313 return $_SERVER['HTTP_X_FORWARDED_FOR'];314 315 } else {316 317 return $_SERVER['REMOTE_ADDR'];318 319 }320 }321 322 /**323 260 * Build the user meta array 324 261 * … … 363 300 return $this->addUserMeta('Profile Link', $profileLink); 364 301 } 365 366 /**367 * Maybe get the users username368 *369 * @return string|false370 */371 protected function maybeGetUsersUsername()372 {373 if (!$this->options->shouldStoreUsername()) {374 return null;375 }376 377 if (!$this->user->isLoggedIn()) {378 return;379 }380 381 return $this->user->userLogin();382 }383 384 302 } -
logtivity/trunk/logtivity.php
r2744371 r2805342 5 5 * Plugin URI: https://logtivity.io 6 6 * Description: Dedicated Event Monitoring for WordPress using Logtivity.io. 7 * Version: 1.20.17 * Version: 2.0 8 8 * Author: Logtivity 9 9 * Text Domain: logtivity … … 12 12 class Logtivity 13 13 { 14 protected $version = ' 1.20.1';14 protected $version = '2.0'; 15 15 16 16 /** … … 26 26 'Admin/Logtivity_Options', 27 27 'Admin/Logtivity_Admin', 28 'Services/Logtivity_User_Logger_Trait', 28 29 'Services/Logtivity_Api', 29 30 'Services/Logtivity_Logger', … … 32 33 'Logs/Logtivity_Abstract_Logger', 33 34 'Services/Logtivity_Check_For_Disabled_Individual_Logs', 35 /** 36 * Error logging 37 */ 38 'Errors/Logtivity_Stack_Trace_Snippet', 39 'Errors/Logtivity_Stack_Trace', 40 'Errors/Logtivity_Error_Logger', 41 'Errors/Logtivity_Error_Log', 34 42 ]; 35 43 … … 40 48 */ 41 49 private $logClasses = [ 50 /** 51 * Activity logging 52 */ 42 53 'Logs/Core/Logtivity_Post', 43 54 'Logs/Core/Logtivity_User', … … 92 103 register_activation_hook( __FILE__, [$this, 'activated']); 93 104 105 add_action( 'upgrader_process_complete', [$this, 'upgradeProcessComplete'], 10, 2); 106 107 add_action( 'activated_plugin', [$this, 'setLogtivityToLoadFirst']); 108 94 109 add_action( 'admin_notices', [$this, 'welcomeMessage']); 95 110 … … 99 114 } 100 115 116 public function upgradeProcessComplete( $upgrader_object, $options ) 117 { 118 if ( $options['type'] != 'plugin' ) { 119 return; 120 } 121 122 if ($options['action'] == 'update') { 123 return $this->setLogtivityToLoadFirst(); 124 } 125 } 126 101 127 public static function log($action = null, $meta = null, $user_id = null) 102 128 { 103 129 return Logtivity_Logger::log($action, $meta, $user_id); 130 } 131 132 public static function logError($error) 133 { 134 return new Logtivity_Error_Logger($error); 104 135 } 105 136 … … 180 211 } 181 212 213 public function setLogtivityToLoadFirst() 214 { 215 $path = str_replace( WP_PLUGIN_DIR . '/', '', __FILE__ ); 216 217 if ( $plugins = get_option( 'active_plugins' ) ) { 218 if ( $key = array_search( $path, $plugins ) ) { 219 array_splice( $plugins, $key, 1 ); 220 array_unshift( $plugins, $path ); 221 update_option( 'active_plugins', $plugins ); 222 } 223 } 224 } 225 182 226 public function welcomeMessage() 183 227 { -
logtivity/trunk/readme.md
r2744371 r2805342 5 5 Requires at least: 4.7 6 6 Tested up to: 6.0 7 Stable tag: 1.20.17 Stable tag: 2.0 8 8 Requires PHP: 7.0 9 9 License: GPLv2 or later … … 226 226 227 227 == Changelog == 228 229 = 2.0 = 230 231 _Release Date – Wednesday 26th October 2022_ 232 233 * Add error logging 234 * Refine Option meta update logging by only logging updates done via a POST request. This avoids logging of less useful updates such as plugins setting last_check/synced timestamps that don't need to be logged. 228 235 229 236 = 1.20.1 = -
logtivity/trunk/readme.txt
r2744371 r2805342 5 5 Requires at least: 4.7 6 6 Tested up to: 6.0 7 Stable tag: 1.20.17 Stable tag: 2.0 8 8 Requires PHP: 7.0 9 9 License: GPLv2 or later … … 226 226 227 227 == Changelog == 228 229 = 2.0 = 230 231 _Release Date – Wednesday 26th October 2022_ 232 233 * Add error logging. 234 * Refine Option meta update logging by only logging updates done via a POST request. This avoids logging of less useful updates such as plugins setting last_check/synced timestamps that don't need to be logged. 228 235 229 236 = 1.20.1 = -
logtivity/trunk/views/settings.php
r2737295 r2805342 181 181 182 182 <?php if ($latest_response['response']): ?> 183 <code style="display: block; padding: 20px; ">183 <code style="display: block; padding: 20px; overflow-x: auto;"> 184 184 185 185 <?php echo sanitize_text_field($latest_response['response']); ?>
Note: See TracChangeset
for help on using the changeset viewer.