| 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 |
/** |
| 26 |
* @var string $fileName |
| 27 |
* @var array $vars |
| 28 |
* @var array $value |
| 29 |
* @var string $key |
| 30 |
* @var array $options |
| 31 |
*/ |
| 32 |
|
| 33 |
$api = new Logtivity_Api(); |
| 34 |
$apiKey = $api->getApiKey(); |
| 35 |
$connectionStatus = $api->getConnectionStatus(); |
| 36 |
$debugLogEntries = (new Logtivity_Debug_Log())->recent(); |
| 37 |
|
| 38 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- logtivity_view() renders trusted plugin templates. |
| 39 |
echo logtivity_view('_admin-header', compact('options')); |
| 40 |
?> |
| 41 |
|
| 42 |
<div class="postbox logtivity-settings"> |
| 43 |
<div class="inside"> |
| 44 |
<h1 style="padding-top: 20px;">Settings</h1> |
| 45 |
|
| 46 |
<?php if (logtivity_has_site_url_changed()): ?> |
| 47 |
<div class="logtivity-notice logtivity-notice-danger"> |
| 48 |
<h2>We've detected a change in your site URL.</h2> |
| 49 |
<div> |
| 50 |
As a precaution, we've stopped logging. To start recording |
| 51 |
logs, again click the 'Update Settings' button below. |
| 52 |
</div> |
| 53 |
</div> |
| 54 |
<?php endif; |
| 55 |
|
| 56 |
if (logtivity_url_environment_mismatch()) : ?> |
| 57 |
<div class="logtivity-notice logtivity-notice-danger"> |
| 58 |
<h2>Logtivity is misconfigured and logging has stopped.</h2> |
| 59 |
<div> |
| 60 |
Your App URL (<?php echo esc_html(logtivity_get_app_url()); ?>) |
| 61 |
and API URL (<?php echo esc_html(logtivity_get_api_url()); ?>) |
| 62 |
point to different environments. Neither |
| 63 |
<code>LOGTIVITY_APP_URL</code> or <code>LOGTIVITY_API_URL</code> |
| 64 |
constant should be set, or both must be set to the same |
| 65 |
non-production environment. No logs will be sent until this is |
| 66 |
corrected. |
| 67 |
</div> |
| 68 |
</div> |
| 69 |
<?php elseif (logtivity_is_production() == false) : ?> |
| 70 |
<div class="logtivity-notice logtivity-notice-warning"> |
| 71 |
<h2>This site is not sending logs to the production application.</h2> |
| 72 |
<div> |
| 73 |
See your dashboard at |
| 74 |
<a target="_blank" |
| 75 |
rel="noopener noreferrer" |
| 76 |
href="<?php echo esc_url(logtivity_get_app_url()); ?>"> |
| 77 |
<?php esc_html_e('Logtivity dashboard', 'logtivity'); ?> |
| 78 |
</a> |
| 79 |
</div> |
| 80 |
</div> |
| 81 |
<?php endif; ?> |
| 82 |
|
| 83 |
<form action="<?php echo esc_url(admin_url('admin-ajax.php?action=logtivity_update_settings')); ?>" method="post"> |
| 84 |
|
| 85 |
<?php wp_nonce_field('logtivity_update_settings', 'logtivity_update_settings') ?> |
| 86 |
|
| 87 |
<table class="form-table"> |
| 88 |
<tbody> |
| 89 |
<tr class="user-user-login-wrap"> |
| 90 |
<th scope="row"> |
| 91 |
<label for="logtivity_site_api_key">Site API Key</label> |
| 92 |
<?php if (has_filter('logtivity_site_api_key')): ?> |
| 93 |
<div class="logtivity-constant">This option has been set in code.</div> |
| 94 |
<?php endif ?> |
| 95 |
</th> |
| 96 |
|
| 97 |
<td> |
| 98 |
<input id="logtivity_site_api_key" |
| 99 |
name="logtivity_site_api_key" |
| 100 |
type="text" |
| 101 |
<?php echo has_filter('logtivity_site_api_key') ? 'readonly' : ''; ?> |
| 102 |
value="<?php echo esc_attr($apiKey); ?>" |
| 103 |
class="regular-text"> |
| 104 |
<p> |
| 105 |
Status: |
| 106 |
<?php |
| 107 |
switch ($connectionStatus) { |
| 108 |
case 'success': |
| 109 |
echo '<span style="color: #4caf50; font-weight: bold;">Connected</span>'; |
| 110 |
break; |
| 111 |
|
| 112 |
case 'paused': |
| 113 |
echo '<span style="color: #dbbf24; font-weight: bold;">Logging is paused</span>'; |
| 114 |
echo '<br>' . esc_html($api->getConnectionMessage()); |
| 115 |
break; |
| 116 |
|
| 117 |
case 'staging': |
| 118 |
echo '<span style="color: #dbbf24; font-weight: bold;">' . esc_html($api->getConnectionMessage()) . '</span>'; |
| 119 |
break; |
| 120 |
|
| 121 |
case 'fail': |
| 122 |
echo '<span style="color: #ff3232; font-weight: bold;">' . esc_html($api->getConnectionMessage()) . '</span>'; |
| 123 |
break; |
| 124 |
|
| 125 |
default: |
| 126 |
if ($apiKey) { |
| 127 |
echo '<span style="color: #ffdd32; font-weight: bold;">Unknown error</span>'; |
| 128 |
} else { |
| 129 |
echo '<span style="font-weight: bold;">Enter this site\'s API Key</span>'; |
| 130 |
} |
| 131 |
break; |
| 132 |
} |
| 133 |
?> |
| 134 |
</p> |
| 135 |
</td> |
| 136 |
|
| 137 |
<td style="vertical-align: top;"> |
| 138 |
<span class="description"> |
| 139 |
You can find this value by logging into your account |
| 140 |
and navigating to this site's settings page. |
| 141 |
</span> |
| 142 |
</td> |
| 143 |
</tr> |
| 144 |
|
| 145 |
<tr class="user-user-login-wrap"> |
| 146 |
<th scope="row"> |
| 147 |
<label for="logtivity_should_store_user_id">Store User ID</label> |
| 148 |
<?php if (has_filter('logtivity_should_store_user_id')): ?> |
| 149 |
<div class="logtivity-constant">This option has been set in code.</div> |
| 150 |
<?php endif ?> |
| 151 |
</th> |
| 152 |
|
| 153 |
<td> |
| 154 |
<input name="logtivity_should_store_user_id" |
| 155 |
type="hidden" |
| 156 |
value="0"> |
| 157 |
|
| 158 |
<input id="logtivity_should_store_user_id" |
| 159 |
name="logtivity_should_store_user_id" |
| 160 |
type="checkbox" |
| 161 |
<?php echo $options['logtivity_should_store_user_id'] ? 'checked' : ''; ?> |
| 162 |
<?php echo has_filter('logtivity_should_store_user_id') ? 'readonly' : ''; ?> |
| 163 |
value="1" |
| 164 |
class="regular-checkbox"> |
| 165 |
</td> |
| 166 |
|
| 167 |
<td> |
| 168 |
<span class="description"> |
| 169 |
If you check this box, when logging an action, |
| 170 |
we will include the users User ID in the logged action. |
| 171 |
</span> |
| 172 |
</td> |
| 173 |
</tr> |
| 174 |
|
| 175 |
<tr class="user-user-login-wrap"> |
| 176 |
<th scope="row"> |
| 177 |
<label for="logtivity_should_log_profile_link">Store Users Profile Link</label> |
| 178 |
<?php if (has_filter('logtivity_should_log_profile_link')): ?> |
| 179 |
<div class="logtivity-constant">This option has been set in code.</div> |
| 180 |
<?php endif ?> |
| 181 |
</th> |
| 182 |
|
| 183 |
<td> |
| 184 |
<input name="logtivity_should_log_profile_link" |
| 185 |
type="hidden" |
| 186 |
value="0"> |
| 187 |
|
| 188 |
<input id="logtivity_should_log_profile_link" |
| 189 |
name="logtivity_should_log_profile_link" |
| 190 |
type="checkbox" |
| 191 |
<?php echo $options['logtivity_should_log_profile_link'] ? 'checked' : ''; ?> |
| 192 |
<?php echo has_filter('logtivity_should_log_profile_link') ? 'readonly' : ''; ?> |
| 193 |
value="1" |
| 194 |
class="regular-checkbox"> |
| 195 |
</td> |
| 196 |
|
| 197 |
<td> |
| 198 |
<span class="description"> |
| 199 |
If you check this box, when logging an action, |
| 200 |
we will include the users profile link in the logged action. |
| 201 |
</span> |
| 202 |
</td> |
| 203 |
</tr> |
| 204 |
|
| 205 |
<tr class="user-user-login-wrap"> |
| 206 |
<th scope="row"> |
| 207 |
<label for="logtivity_should_log_username">Store Users Username</label> |
| 208 |
<?php if (has_filter('logtivity_should_log_username')): ?> |
| 209 |
<div class="logtivity-constant">This option has been set in code.</div> |
| 210 |
<?php endif ?> |
| 211 |
</th> |
| 212 |
|
| 213 |
<td> |
| 214 |
<input name="logtivity_should_log_username" |
| 215 |
type="hidden" |
| 216 |
value="0"> |
| 217 |
|
| 218 |
<input id="logtivity_should_log_username" |
| 219 |
name="logtivity_should_log_username" |
| 220 |
type="checkbox" |
| 221 |
<?php echo has_filter('logtivity_should_log_username') ? 'readonly' : ''; ?> |
| 222 |
<?php echo $options['logtivity_should_log_username'] ? 'checked' : ''; ?> |
| 223 |
value="1" |
| 224 |
class="regular-checkbox"> |
| 225 |
</td> |
| 226 |
|
| 227 |
<td> |
| 228 |
<span class="description"> |
| 229 |
If you check this box, when logging an action, |
| 230 |
we will include the users username in the logged action. |
| 231 |
</span> |
| 232 |
</td> |
| 233 |
</tr> |
| 234 |
|
| 235 |
<tr class="user-user-login-wrap"> |
| 236 |
<th scope="row"> |
| 237 |
<label for="logtivity_should_store_ip">Store Users IP Address</label> |
| 238 |
<?php if (has_filter('logtivity_should_store_ip')): ?> |
| 239 |
<div class="logtivity-constant">This option has been set in code.</div> |
| 240 |
<?php endif ?> |
| 241 |
</th> |
| 242 |
|
| 243 |
<td> |
| 244 |
<input name="logtivity_should_store_ip" |
| 245 |
type="hidden" |
| 246 |
value="0"> |
| 247 |
|
| 248 |
<input id="logtivity_should_store_ip" |
| 249 |
name="logtivity_should_store_ip" |
| 250 |
type="checkbox" |
| 251 |
<?php echo $options['logtivity_should_store_ip'] ? 'checked' : ''; ?> |
| 252 |
<?php echo has_filter('logtivity_should_store_ip') ? 'readonly' : ''; ?> |
| 253 |
value="1" |
| 254 |
class="regular-checkbox"> |
| 255 |
</td> |
| 256 |
|
| 257 |
<td> |
| 258 |
<span class="description"> |
| 259 |
If you check this box, when logging an action, |
| 260 |
we will include the users IP address in the logged action. |
| 261 |
</span> |
| 262 |
</td> |
| 263 |
</tr> |
| 264 |
|
| 265 |
<tr class="user-user-login-wrap"> |
| 266 |
<th scope="row"> |
| 267 |
<label for="logtivity_app_verify_url"> |
| 268 |
Verify Site URL |
| 269 |
</label> |
| 270 |
<?php if (has_filter('logtivity_app_verify_url')): ?> |
| 271 |
<div class="logtivity-constant">This option has been set in code.</div> |
| 272 |
<?php endif ?> |
| 273 |
</th> |
| 274 |
|
| 275 |
<td> |
| 276 |
<input name="logtivity_app_verify_url" |
| 277 |
type="hidden" |
| 278 |
value="0"> |
| 279 |
|
| 280 |
<input id="logtivity_app_verify_url" |
| 281 |
name="logtivity_app_verify_url" |
| 282 |
type="checkbox" |
| 283 |
<?php echo $options['logtivity_app_verify_url'] ? 'checked' : ''; ?> |
| 284 |
<?php echo has_filter('logtivity_app_verify_url') ? 'readonly' : ''; ?> |
| 285 |
value="1" |
| 286 |
class="regular-checkbox"> |
| 287 |
</td> |
| 288 |
|
| 289 |
<td> |
| 290 |
<span class="description"> |
| 291 |
When messages are sent to Logtivity, the site URL will be checked |
| 292 |
against the URL Logtivity has on file for this API Key. If they do |
| 293 |
not match, logging will be paused. |
| 294 |
</span> |
| 295 |
</td> |
| 296 |
</tr> |
| 297 |
|
| 298 |
<tr class="user-user-login-wrap"> |
| 299 |
<th scope="row"> |
| 300 |
<label for="logtivity_enable_debug_mode"> |
| 301 |
Enable debug mode (recommended off by default) |
| 302 |
</label> |
| 303 |
<?php if (has_filter('logtivity_enable_debug_mode')): ?> |
| 304 |
<div class="logtivity-constant">This option has been set in code.</div> |
| 305 |
<?php endif ?> |
| 306 |
</th> |
| 307 |
|
| 308 |
<td> |
| 309 |
<input name="logtivity_enable_debug_mode" |
| 310 |
type="hidden" |
| 311 |
value="0"> |
| 312 |
|
| 313 |
<input id="logtivity_enable_debug_mode" |
| 314 |
name="logtivity_enable_debug_mode" |
| 315 |
type="checkbox" |
| 316 |
<?php echo $options['logtivity_enable_debug_mode'] ? 'checked' : ''; ?> |
| 317 |
<?php echo has_filter('logtivity_enable_debug_mode') ? 'readonly' : ''; ?> |
| 318 |
value="1" |
| 319 |
class="regular-checkbox"> |
| 320 |
</td> |
| 321 |
|
| 322 |
<td> |
| 323 |
<span class="description"> |
| 324 |
This will record a history of request and response data for API calls |
| 325 |
to a debug log file (<code>wp-content/uploads/logtivity-logs/debug.log</code>), |
| 326 |
viewable below. Response details are only captured for calls that already |
| 327 |
wait for a response (periodic settings check-ins, roughly every 10 minutes); |
| 328 |
other calls are still sent without waiting and only the outgoing request is |
| 329 |
logged. Enabling this does not affect performance. |
| 330 |
</span> |
| 331 |
</td> |
| 332 |
</tr> |
| 333 |
|
| 334 |
<tr class="user-user-login-wrap"> |
| 335 |
<th scope="row"> |
| 336 |
<label for="logtivity_disable_individual_logs">Disable Individual Logs</label> |
| 337 |
<?php if (has_filter('logtivity_disable_individual_logs')): ?> |
| 338 |
<div class="logtivity-constant">This option has been set in code.</div> |
| 339 |
<?php endif ?> |
| 340 |
</th> |
| 341 |
<td> |
| 342 |
<textarea id="logtivity_disable_individual_logs" |
| 343 |
name="logtivity_disable_individual_logs" |
| 344 |
class="regular-checkbox" |
| 345 |
style="width: 100%;" |
| 346 |
<?php echo has_filter('logtivity_disable_individual_logs') ? 'readonly' : ''; ?> |
| 347 |
rows="10" |
| 348 |
placeholder="User Logged In User Created && subscriber" |
| 349 |
><?php echo esc_html($options['logtivity_disable_individual_logs']); ?></textarea> |
| 350 |
</td> |
| 351 |
|
| 352 |
<td> |
| 353 |
<span class="description"> |
| 354 |
You can disable individual logged actions here by listing the action names, one per line. |
| 355 |
<br> |
| 356 |
<br> |
| 357 |
To specify the context field as well, |
| 358 |
separate the action and context keywords with an && symbol. |
| 359 |
<br> |
| 360 |
<br> |
| 361 |
<?php |
| 362 |
if ( |
| 363 |
isset($options['logtivity_enable_white_label_mode']) == false |
| 364 |
|| $options['logtivity_enable_white_label_mode'] != 1 |
| 365 |
): |
| 366 |
?> |
| 367 |
If you have multiple sites on Logtivity and would rather control disabled |
| 368 |
logs globally you can go to the |
| 369 |
<?php |
| 370 |
printf( |
| 371 |
'<a href="%s" target="_blank" rel="nofollow">%s</a>', |
| 372 |
esc_url(logtivity_get_app_url() . '/team-settings/activity-log-settings'), |
| 373 |
esc_html__('Activity Log Settings page', 'logtivity') |
| 374 |
); |
| 375 |
?> |
| 376 |
in your Logtivity dashboard. |
| 377 |
<?php endif; ?> |
| 378 |
</span> |
| 379 |
</td> |
| 380 |
</tr> |
| 381 |
</tbody> |
| 382 |
</table> |
| 383 |
|
| 384 |
<p class="submit"> |
| 385 |
<input id="submit" |
| 386 |
name="submit" |
| 387 |
type="submit" |
| 388 |
class="button button-primary" |
| 389 |
value="Update Settings"> |
| 390 |
</p> |
| 391 |
</form> |
| 392 |
|
| 393 |
</div> |
| 394 |
</div> |
| 395 |
|
| 396 |
<?php if ($options['logtivity_enable_debug_mode']): ?> |
| 397 |
|
| 398 |
<div class="postbox"> |
| 399 |
<div class="inside"> |
| 400 |
|
| 401 |
<h3>Debug Log</h3> |
| 402 |
|
| 403 |
<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" style="display: inline-block; margin-bottom: 15px;"> |
| 404 |
<input type="hidden" name="action" value="logtivity_clear_debug_log"> |
| 405 |
<?php wp_nonce_field('logtivity_clear_debug_log', 'logtivity_clear_debug_log'); ?> |
| 406 |
<input id="logtivity-clear-debug-log" |
| 407 |
type="submit" |
| 408 |
class="button" |
| 409 |
value="Clear Debug Log" |
| 410 |
onclick="return confirm('Are you sure you want to clear the debug log?');"> |
| 411 |
</form> |
| 412 |
|
| 413 |
<?php if ($debugLogEntries) : ?> |
| 414 |
<a id="logtivity-download-debug-log" |
| 415 |
class="button" |
| 416 |
style="margin-bottom: 15px;" |
| 417 |
href="<?php |
| 418 |
echo esc_url(wp_nonce_url( |
| 419 |
admin_url('admin-post.php?action=logtivity_download_debug_log'), |
| 420 |
'logtivity_download_debug_log', |
| 421 |
'logtivity_download_debug_log' |
| 422 |
)); |
| 423 |
?>"> |
| 424 |
Download Debug Log |
| 425 |
</a> |
| 426 |
<?php endif; ?> |
| 427 |
|
| 428 |
<?php if ($debugLogEntries) : ?> |
| 429 |
<?php foreach ($debugLogEntries as $entry) : ?> |
| 430 |
<div style="border-bottom: 1px solid #ddd; padding: 10px 0;"> |
| 431 |
<h4> |
| 432 |
<?php echo esc_html($entry['timestamp'] ?? ''); ?> |
| 433 |
— |
| 434 |
<?php echo esc_html($entry['method'] ?? ''); ?> |
| 435 |
<?php echo esc_html($entry['endpoint'] ?? ''); ?> |
| 436 |
</h4> |
| 437 |
<?php $responseCode = $entry['response_code'] ?? null; ?> |
| 438 |
<h4> |
| 439 |
Response: |
| 440 |
<?php |
| 441 |
echo $responseCode === null |
| 442 |
? 'not captured (sent without waiting for a response)' |
| 443 |
: esc_html(sprintf( |
| 444 |
'%s - %s (%sms)', |
| 445 |
$responseCode, |
| 446 |
$entry['response_message'] ?? 'No Message', |
| 447 |
$entry['response_time_ms'] ?? 'NA' |
| 448 |
)); |
| 449 |
?> |
| 450 |
</h4> |
| 451 |
<code style="display: block; padding: 20px; overflow-x: auto;"> |
| 452 |
Request: <?php echo esc_html(wp_json_encode($entry['request_body'] ?? null)); ?> |
| 453 |
</code> |
| 454 |
<?php if ($responseCode !== null) : ?> |
| 455 |
<code style="display: block; padding: 20px; overflow-x: auto;"> |
| 456 |
Response: <?php echo esc_html(wp_json_encode($entry['response_body'] ?? null)); ?> |
| 457 |
</code> |
| 458 |
<?php endif; ?> |
| 459 |
</div> |
| 460 |
<?php endforeach; ?> |
| 461 |
<?php else : ?> |
| 462 |
<p>The debug log will appear here after an API call has been made.</p> |
| 463 |
<?php endif; ?> |
| 464 |
</div> |
| 465 |
</div> |
| 466 |
|
| 467 |
<?php endif ?> |
| 468 |
|
| 469 |
<?php |
| 470 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- logtivity_view() renders trusted plugin templates. |
| 471 |
echo logtivity_view('_admin-footer', compact('options')); |
| 472 |
?> |
| 473 |
|