PluginProbe
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity / 3.3.10
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity v3.3.10
3.3.10 3.3.9 3.3.8 trunk 1.0 1.1.0 1.10.0 1.11.0 1.11.1 1.12.0 1.13.0 1.14.0 1.15.0 1.16.0 1.17.0 1.17.1 1.18.0 1.19.0 1.2.0 1.20.0 1.20.1 1.3.0 1.3.1 1.4.0 1.5.0 All 68 releases
logtivity / Loggers / Core / Logtivity_Core.php

Logtivity_Core.php in Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity 3.3.10, at Loggers/Core/Logtivity_Core.php

293 lines 8.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @package Logtivity
5 * @contact logtivity.io, [email protected]
6 * @copyright 2024-2026 Logtivity. All rights reserved
7 * @license https://www.gnu.org/licenses/gpl.html GNU/GPL
8 *
9 * This file is part of Logtivity.
10 *
11 * Logtivity is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * Logtivity is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with Logtivity. If not, see <https://www.gnu.org/licenses/>.
23 */
24
25 class Logtivity_Core extends Logtivity_Abstract_Logger
26 {
27 /**
28 * @var string[]
29 */
30 protected array $ignoredOptions = [
31 '_edd_table_check',
32 '_wp_suggested_policy_text_has_changed',
33 'action_scheduler_lock_async-request-runner',
34 'active_plugins',
35 'admin_email_lifespan',
36 'adminhash',
37 'akismet_spam_count',
38 'allowedthemes',
39 'auto_plugin_theme_update_emails',
40 'cron',
41 'db_upgraded',
42 'delete_blog_hash',
43 'fresh_site',
44 'ftp_credentials',
45 'gmt_offset',
46 'jetpack_next_sync_time_sync',
47 'jetpack_plugin_api_action_links',
48 'jetpack_protect_blocked_attempts',
49 'jetpack_sync_settings_dedicated_sync_enabled',
50 'jetpack_updates_sync_checksum',
51 'jp_sync_last_success_sync',
52 'jp_sync_retry_after_sync',
53 'limit_login_retries',
54 'mepr_coupons_expire_last_run',
55 'mepr_groups_db_cleanup_last_run',
56 'mepr_products_db_cleanup_last_run',
57 'mepr_rules_db_cleanup_last_run',
58 'post_views_count',
59 'postman_state',
60 'recently_activated',
61 'recently_edited',
62 'rewrite_rules',
63 'rxpp_blocked_methods_count',
64 'stats_cache',
65 'uninstall_plugins',
66 'woocommerce_marketplace_suggestions',
67 'wordfence_syncAttackDataAttempts',
68 'wp_all_export_pro_addons_not_included',
69 'wp_force_deactivated_plugins',
70 'wpcf7',
71 'ws_form_css',
72 ];
73
74 /**
75 * @var string[]
76 */
77 protected array $ignoredWildcardOptions = [
78 'auto_updater',
79 'cache',
80 'cron',
81 'edd_api',
82 'edd_sl',
83 'frm_',
84 'last_run',
85 'logtivity_api',
86 'logtivity_app',
87 'logtivity_custom_plugin_name',
88 'logtivity_disable',
89 'logtivity_enable',
90 'logtivity_global',
91 'logtivity_hide_plugin_from_ui',
92 'logtivity_last_settings_check_in_at',
93 'logtivity_latest_response',
94 'logtivity_should',
95 'logtivity_site_api_key',
96 'logtivity_url_hash',
97 'logtivity_version',
98 'queue',
99 'sync',
100 'transient',
101 'wpe',
102 ];
103
104 /**
105 * @inheritDoc
106 */
107 protected function registerHooks(): void
108 {
109 add_action('upgrader_process_complete', [$this, 'upgradeProcessComplete'], 10, 2);
110 add_action('wp_update_nav_menu', [$this, 'menuUpdated'], 10, 2);
111 add_action('init', [$this, 'maybeSettingsUpdated'], 10, 1);
112 add_action('permalink_structure_changed', [$this, 'permalinksUpdated'], 10, 2);
113
114 if (get_option('logtivity_enable_options_table_logging')) {
115 add_action('update_option', [$this, 'optionUpdated'], 10, 3);
116 }
117
118 add_filter('widget_update_callback', [$this, 'widgetUpdated'], 10, 4);
119 }
120
121 /**
122 * @param WP_Upgrader $upgrader
123 * @param array $options
124 *
125 * @return void
126 */
127 public function upgradeProcessComplete(WP_Upgrader $upgrader, array $options): void
128 {
129 $type = $options['type'] ?? null;
130 if ($type == 'core') {
131 $action = $options['action'] ?? null;
132
133 switch ($action) {
134 case 'update':
135 Logtivity::log('WP Core Updated')->send();
136 break;
137
138 case 'install':
139 Logtivity::log('WP Core Installed')->send();
140 break;
141 }
142 }
143 }
144
145 /**
146 * @param int $menuId
147 * @param ?array $menuData
148 *
149 * @return void
150 */
151 public function menuUpdated(int $menuId, ?array $menuData = null): void
152 {
153 $menuName = $menuData['menu-name'] ?? null;
154
155 if ($menuName) {
156 Logtivity::log()
157 ->setAction('Menu Updated')
158 ->setContext($menuName)
159 ->addMeta('Menu ID', $menuId)
160 ->send();
161 }
162 }
163
164 /**
165 * @param array $currentSettings
166 * @param array $newSettings
167 * @param array $oldSettings
168 * @param WP_Widget $widget
169 *
170 * @return array
171 */
172 public function widgetUpdated(
173 array $currentSettings,
174 array $newSettings,
175 array $oldSettings,
176 WP_Widget $widget
177 ): array {
178 Logtivity::log()
179 ->setAction('Widget Updated')
180 ->setContext($widget->name)
181 ->addMeta('New Content', $newSettings)
182 ->addMeta('Old Content', $oldSettings)
183 ->send();
184
185 return $currentSettings;
186 }
187
188 /**
189 * @TODO: When does this get called?
190 *
191 * @return void
192 */
193 public function maybeSettingsUpdated(): void
194 {
195 // phpcs:disable WordPress.Security.NonceVerification.Missing -- Passive logger reads core settings request after WordPress validates it.
196 $optionPage = isset($_POST['option_page'])
197 ? sanitize_text_field(wp_unslash($_POST['option_page']))
198 : '';
199 $action = isset($_POST['action'])
200 ? sanitize_text_field(wp_unslash($_POST['action']))
201 : '';
202 // phpcs:enable WordPress.Security.NonceVerification.Missing
203
204 if ($optionPage && $action == 'update') {
205 Logtivity::log()
206 ->setAction('Settings Updated')
207 ->setContext('Core:' . $optionPage)
208 ->send();
209 }
210 }
211
212 /**
213 * @param string $option
214 *
215 * @return bool
216 */
217 protected function ignoreOption(string $option): bool
218 {
219 $ignore = in_array($option, $this->ignoredOptions) !== false;
220 if ($ignore == false) {
221 foreach ($this->ignoredWildcardOptions as $wildcard) {
222 if (strpos($option, $wildcard) !== false) {
223 return true;
224 }
225 }
226 }
227
228 return $ignore;
229 }
230
231 /**
232 * @param string $option
233 * @param mixed $oldValue
234 * @param mixed $newValue
235 *
236 * @return void
237 */
238 public function optionUpdated(string $option, $oldValue, $newValue): void
239 {
240 if (
241 $this->getRequestMethod() != 'GET'
242 && is_admin()
243 && $oldValue !== $newValue
244 && $this->ignoreOption($option) == false
245 && get_option('logtivity_enable_options_table_logging')
246 ) {
247 Logtivity::log()
248 ->setAction('Option Updated')
249 ->setContext($option)
250 ->addMetaIf(is_scalar($oldValue), 'Old Value', $oldValue)
251 ->addMetaIf(is_scalar($newValue), 'New Value', $newValue)
252 ->send();
253 }
254 }
255
256 /**
257 * @return string
258 */
259 private function getRequestMethod(): string
260 {
261 return isset($_SERVER['REQUEST_METHOD'])
262 ? sanitize_text_field(wp_unslash($_SERVER['REQUEST_METHOD']))
263 : '';
264 }
265
266 /**
267 * @param string $oldStructure
268 * @param string $newStructure
269 *
270 * @return void
271 */
272 public function permalinksUpdated(string $oldStructure, string $newStructure): void
273 {
274 Logtivity::log()
275 ->setAction('Permalinks Updated')
276 ->setContext($this->getPermalinkStructure($newStructure))
277 ->addMeta('Old Structure', $this->getPermalinkStructure($oldStructure))
278 ->send();
279 }
280
281 /**
282 * @param string $structure
283 *
284 * @return string
285 */
286 private function getPermalinkStructure(string $structure): string
287 {
288 return $structure ?: 'Plain';
289 }
290 }
291
292 new Logtivity_Core();
293