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