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
← All changes | Core/Admin/Logtivity_Options.php +38 -10 3.3.9 → 3.3.10 View file →
@@ -154,9 +154,9 @@
154 154 * @return bool
155 155 */
156 156 public function shouldLogLatestResponse(): bool
157 157 {
158 - return $this->getOption('logtivity_enable_debug_mode') || $this->shouldCheckInWithApi();
158 + return $this->shouldCheckInWithApi();
159 159 }
160 160
161 161 /**
162 162 * @return bool
@@ -162,15 +162,13 @@
162 162 * @return bool
163 163 */
164 164 public function shouldCheckInWithApi(): bool
165 165 {
166 - if ($this->getOption('logtivity_enable_debug_mode') == false) {
167 - $lastCheckin = get_option('logtivity_last_settings_check_in_at');
168 - $lastCheckin = $lastCheckin['date'] ?? null;
166 + $lastCheckin = get_option('logtivity_last_settings_check_in_at');
167 + $lastCheckin = $lastCheckin['date'] ?? null;
169 168
170 - if ($lastCheckin) {
171 - return time() - strtotime($lastCheckin) > $this->checkinDelay;
172 - }
169 + if ($lastCheckin) {
170 + return time() - strtotime($lastCheckin) > $this->checkinDelay;
173 171 }
174 172
175 173 return true;
176 174 }
@@ -224,10 +222,22 @@
224 222 * @return void
225 223 */
226 224 public function update(array $data = [], bool $checkApiKey = true): void
227 225 {
228 - $settings = array_intersect_key($data ?: $_POST, $this->settings);
226 + if (!$data) {
227 + if (!current_user_can(Logtivity::ACCESS_SETTINGS)) {
228 + return;
229 + }
230 +
231 + check_ajax_referer('logtivity_update_settings', 'logtivity_update_settings');
232 +
233 + $data = wp_unslash($_POST);
234 + }
235 +
236 + $settings = array_intersect_key($data, $this->settings);
229 237 foreach ($settings as $key => $value) {
238 + $value = $this->sanitizeSetting($key, $value);
239 +
230 240 if ($this->validateSetting($key, $value)) {
231 241 update_option($key, $value);
232 242 }
233 243 }
@@ -232,11 +242,29 @@
232 242 }
233 243 }
234 244
235 245 if ($checkApiKey) {
236 - $this->checkApiKey($data['logtivity_site_api_key']
237 - ?? sanitize_text_field($_POST['logtivity_site_api_key'] ?? null));
246 + $this->checkApiKey($settings['logtivity_site_api_key'] ?? null);
238 247 }
248 + }
249 +
250 + /**
251 + * Sanitize setting values before saving.
252 + *
253 + * @param string $key
254 + * @param mixed $value
255 + *
256 + * @return mixed
257 + */
258 + protected function sanitizeSetting(string $key, $value)
259 + {
260 + $setting = $this->settings[$key] ?? null;
261 +
262 + if (($setting['rule'] ?? null) === 'is_string' && is_scalar($value)) {
263 + return sanitize_textarea_field((string)$value);
264 + }
265 +
266 + return $value;
239 267 }
240 268
241 269 /**
242 270 * Validate that the passed parameters are in the correct format