Plugin Directory

source: wp-security-audit-log/trunk/classes/Views/Settings.php

Last change on this file was 3240221, checked in by melapress, 2 months ago

Uploading 5.3.1

File size: 82.4 KB
Line 
1<?php
2/**
3 * Settings Page
4 *
5 * Settings page of the plugin.
6 *
7 * @since      1.0.0
8 * @package    wsal
9 * @subpackage views
10 */
11
12use WSAL\Helpers\WP_Helper;
13use WSAL\Helpers\User_Helper;
14use WSAL\Controllers\Constants;
15use WSAL\Controllers\Connection;
16use WSAL\Helpers\Settings_Helper;
17use WSAL\Controllers\Alert_Manager;
18use WSAL\Controllers\Database_Manager;
19use WSAL\Helpers\Plugin_Settings_Helper;
20use WSAL\Entities\Archive\Delete_Records;
21
22// Exit if accessed directly.
23if ( ! defined( 'ABSPATH' ) ) {
24        exit;
25}
26
27/**
28 * Class: WSAL_Views_Settings
29 *
30 * Settings view class to handle settings page functions.
31 *
32 * @since      1.0.0
33 *
34 * @package    wsal
35 * @subpackage views
36 */
37class WSAL_Views_Settings extends WSAL_AbstractView {
38
39        /**
40         * Adapter Message.
41         *
42         * @var string
43         */
44        public $adapter_msg = '';
45
46        /**
47         * WSAL Setting Tabs.
48         *
49         * @since 3.2.3
50         *
51         * @var array
52         */
53        private $wsal_setting_tabs = array();
54
55        /**
56         * Current Setting Tab.
57         *
58         * @since 3.2.3
59         *
60         * @var string
61         */
62        private $current_tab = '';
63
64        /**
65         * Method: Constructor.
66         *
67         * @param WpSecurityAuditLog $plugin - Instance of WpSecurityAuditLog.
68         */
69        public function __construct( $plugin ) {
70                if ( null === $plugin ) {
71                        $plugin = WpSecurityAuditLog::get_instance();
72                }
73                parent::__construct( $plugin );
74                add_action( 'admin_init', array( $this, 'setup_settings_tabs' ) );
75                add_action( 'wp_ajax_AjaxCheckSecurityToken', array( $this, 'ajax_check_security_token' ) );
76                add_action( 'wp_ajax_AjaxRunCleanup', array( $this, 'ajax_run_cleanup' ) );
77                add_action( 'wp_ajax_AjaxGetAllUsers', array( $this, 'ajax_get_all_users' ) );
78                add_action( 'wp_ajax_AjaxGetAllRoles', array( $this, 'ajax_get_all_roles' ) );
79                add_action( 'wp_ajax_AjaxGetAllCPT', array( $this, 'ajax_get_all_cpts' ) );
80                add_action( 'wp_ajax_AjaxGetAllStatuses', array( $this, 'ajax_get_all_stati' ) );
81                add_action( 'wp_ajax_wsal_reset_settings', array( $this, 'reset_settings' ) );
82                add_action( 'wp_ajax_wsal_purge_activity', array( $this, 'purge_activity' ) );
83                add_action( 'wp_ajax_wsal_ajax_get_all_severities', array( $this, 'ajax_get_all_severities' ) );
84                add_action( 'wp_ajax_wsal_ajax_get_all_event_types', array( $this, 'ajax_get_all_event_types' ) );
85                add_action( 'wp_ajax_wsal_ajax_get_all_object_types', array( $this, 'ajax_get_all_object_types' ) );
86                add_action( 'wp_ajax_wsal_ajax_get_all_event_ids', array( $this, 'ajax_get_all_event_ids' ) );
87        }
88
89        /**
90         * Setup WSAL Settings Page Tabs.
91         *
92         * @since 3.4
93         */
94        public function setup_settings_tabs() {
95
96                // Verify that the current page is WSAL settings page.
97                $page = isset( $_GET['page'] ) ? \sanitize_text_field( wp_unslash( $_GET['page'] ) ) : false;
98                if ( empty( $page ) || $this->get_safe_view_name() !== $page ) {
99                        return;
100                }
101
102                // Tab links.
103                $wsal_setting_tabs = array(
104                        'general'           => array(
105                                'name'     => esc_html__( 'General', 'wp-security-audit-log' ),
106                                'link'     => add_query_arg( 'tab', 'general', $this->get_url() ),
107                                'render'   => array( $this, 'tab_general' ),
108                                'save'     => array( $this, 'tab_general_save' ),
109                                'priority' => 10,
110                        ),
111                        'audit-log'         => array(
112                                'name'     => esc_html__( 'Activity log viewer', 'wp-security-audit-log' ),
113                                'link'     => add_query_arg( 'tab', 'audit-log', $this->get_url() ),
114                                'render'   => array( $this, 'tab_audit_log' ),
115                                'save'     => array( $this, 'tab_audit_log_save' ),
116                                'priority' => 20,
117                        ),
118                        'file-changes'      => array(
119                                'name'     => esc_html__( 'File changes', 'wp-security-audit-log' ),
120                                'link'     => add_query_arg( 'tab', 'file-changes', $this->get_url() ),
121                                'render'   => array( $this, 'tab_file_changes' ),
122                                'priority' => 30,
123                        ),
124                        'exclude-objects'   => array(
125                                'name'     => esc_html__( 'Exclude objects', 'wp-security-audit-log' ),
126                                'link'     => add_query_arg( 'tab', 'exclude-objects', $this->get_url() ),
127                                'render'   => array( $this, 'tab_exclude_objects' ),
128                                'save'     => array( $this, 'tab_exclude_objects_save' ),
129                                'priority' => 40,
130                        ),
131                        'advanced-settings' => array(
132                                'name'     => esc_html__( 'Advanced settings', 'wp-security-audit-log' ),
133                                'link'     => add_query_arg( 'tab', 'advanced-settings', $this->get_url() ),
134                                'render'   => array( $this, 'tab_advanced_settings' ),
135                                'save'     => array( $this, 'tab_advanced_settings_save' ),
136                                'priority' => 100,
137                        ),
138                );
139
140                /**
141                 * Filter: `wsal_setting_tabs`
142                 *
143                 * This filter is used to filter the tabs of WSAL settings page.
144                 *
145                 * Setting tabs structure:
146                 *     $wsal_setting_tabs['unique-tab-id'] = array(
147                 *         'name'     => Name of the tab,
148                 *         'link'     => Link of the tab,
149                 *         'render'   => This function is used to render HTML elements in the tab,
150                 *         'name'     => This function is used to save the related setting of the tab,
151                 *         'priority' => Priority of the tab,
152                 *     );
153                 *
154                 * @param array $wsal_setting_tabs – Array of WSAL Setting Tabs.
155                 *
156                 * @since 3.2.3
157                 */
158                $wsal_setting_tabs = apply_filters( 'wsal_setting_tabs', $wsal_setting_tabs );
159
160                // Sort by priority.
161                array_multisort( array_column( $wsal_setting_tabs, 'priority' ), SORT_ASC, $wsal_setting_tabs );
162
163                $this->wsal_setting_tabs = $wsal_setting_tabs;
164
165                // Get the current tab.
166                $current_tab       = ( isset( $_GET['tab'] ) ) ? \sanitize_text_field( \wp_unslash( $_GET['tab'] ) ) : '';
167                $this->current_tab = empty( $current_tab ) ? 'general' : $current_tab;
168        }
169
170        /**
171         * {@inheritDoc}
172         */
173        public function has_plugin_shortcut_link() {
174                return true;
175        }
176
177        /**
178         * {@inheritDoc}
179         */
180        public function get_title() {
181                return esc_html__( 'Settings', 'wp-security-audit-log' );
182        }
183
184        /**
185         * {@inheritDoc}
186         */
187        public function get_icon() {
188                return 'dashicons-admin-generic';
189        }
190
191        /**
192         * {@inheritDoc}
193         */
194        public function get_name() {
195                return esc_html__( 'Settings', 'wp-security-audit-log' );
196        }
197
198        /**
199         * {@inheritDoc}
200         */
201        public function get_weight() {
202                return 8;
203        }
204
205        /**
206         * Method: Save settings.
207         *
208         * @throws Exception - Unrecognized settings tab error.
209         */
210        protected function save() {
211                // Bail early if user does not have sufficient permissions to save.
212                if ( ! Settings_Helper::current_user_can( 'edit' ) ) {
213                        throw new Exception( esc_html__( 'Current user is not allowed to save settings.', 'wp-security-audit-log' ) );
214                }
215                // Call respective tab save functions if they are set. Nonce is already verified at this point.
216                if ( ! empty( $this->current_tab ) && ! empty( $this->wsal_setting_tabs[ $this->current_tab ]['save'] ) ) {
217                        call_user_func( $this->wsal_setting_tabs[ $this->current_tab ]['save'] );
218                } else {
219                        throw new Exception( esc_html__( 'Unknown settings tab.', 'wp-security-audit-log' ) );
220                }
221        }
222
223        /**
224         * Method: Check security token.
225         */
226        public function ajax_check_security_token() {
227                if ( ! Settings_Helper::current_user_can( 'edit' ) ) {
228                        echo wp_json_encode(
229                                array(
230                                        'success' => false,
231                                        'message' => esc_html__( 'Access Denied.', 'wp-security-audit-log' ),
232                                )
233                        );
234                        die();
235                }
236
237                $nonce = isset( $_POST['nonce'] ) ? \sanitize_text_field( \wp_unslash( $_POST['nonce'] ) ) : false;
238                $token = isset( $_POST['token'] ) ? \sanitize_text_field( \wp_unslash( $_POST['token'] ) ) : false;
239
240                if ( empty( $nonce ) || ! \wp_verify_nonce( $nonce, 'wsal-exclude-nonce' ) ) {
241                        echo wp_json_encode(
242                                array(
243                                        'success' => false,
244                                        'message' => esc_html__( 'Nonce verification failed.', 'wp-security-audit-log' ),
245                                )
246                        );
247                        die();
248                }
249
250                if ( empty( $token ) ) {
251                        echo wp_json_encode(
252                                array(
253                                        'success' => false,
254                                        'message' => esc_html__( 'Invalid input.', 'wp-security-audit-log' ),
255                                )
256                        );
257                        die();
258                }
259
260                $input_type = isset( $_POST['type'] ) ? \sanitize_text_field( \wp_unslash( $_POST['type'] ) ) : false;
261
262                echo wp_json_encode(
263                        array(
264                                'success'   => true,
265                                'token'     => $token,
266                                'tokenType' => esc_html( Plugin_Settings_Helper::get_token_type( $token, $input_type ) ),
267                        )
268                );
269                die();
270        }
271
272        /**
273         * Method: Run cleanup.
274         */
275        public function ajax_run_cleanup() {
276                // Verify nonce.
277                if ( ! isset( $_REQUEST['nonce'] ) || false === wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_REQUEST['nonce'] ) ), 'wsal-run-cleanup' ) ) {
278                        wp_send_json_error( esc_html__( 'Insecure request.', 'wp-security-audit-log' ) );
279                }
280
281                if ( ! Settings_Helper::current_user_can( 'edit' ) ) {
282                        die( 'Access Denied.' );
283                }
284
285                $now       = time();
286                $max_sdate = Plugin_Settings_Helper::get_pruning_date(); // Pruning date.
287                $archiving = Settings_Helper::is_archiving_set_and_enabled();
288
289                // phpcs:disable
290                // phpcs:enable
291
292                // Calculate limit timestamp.
293                $max_stamp = $now - ( strtotime( $max_sdate ) - $now );
294
295                $items = array();
296
297                if ( $archiving ) {
298                        $connection_name = Settings_Helper::get_option_value( 'archive-connection' );
299
300                        $wsal_db = Connection::get_connection( $connection_name );
301
302                        $items = Delete_Records::delete( array(), 0, array( 'created_on <= %s' => intval( $max_stamp ) ), $wsal_db );
303                }
304
305                $main_items = Delete_Records::delete( array(), 0, array( 'created_on <= %s' => intval( $max_stamp ) ) );
306
307                if ( $archiving ) {
308                        $archiving_args = array(
309                                'page' => 'wsal-ext-settings',
310                                'tab'  => 'archiving',
311                        );
312                        $archiving_url  = add_query_arg( $archiving_args, \network_admin_url( 'admin.php' ) );
313                        wp_safe_redirect( $archiving_url );
314                } else {
315                        if ( ( is_array( $items ) && count( $items ) ) || ( is_array( $main_items ) && count( $main_items ) ) ) {
316                                $redirect_args = array(
317                                        'tab'     => 'audit-log',
318                                        'pruning' => 1,
319                                );
320                        } else {
321                                $redirect_args = array(
322                                        'tab'     => 'audit-log',
323                                        'pruning' => 0,
324                                );
325                        }
326                        wp_safe_redirect( add_query_arg( $redirect_args, $this->get_url() ) );
327                }
328                exit;
329        }
330
331        /**
332         * {@inheritDoc}
333         */
334        public function render() {
335                // Verify nonce if a form is submitted.
336                if ( isset( $_POST['_wpnonce'] ) ) {
337                        check_admin_referer( 'wsal-settings' );
338                }
339
340                if ( ! Settings_Helper::current_user_can( 'edit' ) ) {
341                        wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'wp-security-audit-log' ) );
342                }
343
344                // Check to see if section parameter is set in the URL.
345                $section = isset( $_GET['section'] ) ? \sanitize_text_field( wp_unslash( $_GET['section'] ) ) : false;
346
347                if ( isset( $_POST['submit'] ) ) {
348                        try {
349                                $this->save(); // Save settings.
350                                if ( 'sms-provider' === $this->current_tab && $section && 'test' === $section ) :
351                                        ?>
352                                        <div class="updated">
353                                                <p><?php esc_html_e( 'Message sent successfully.', 'wp-security-audit-log' ); ?></p>
354                                        </div>
355                                <?php else : ?>
356                                        <div class="updated">
357                                                <p><?php esc_html_e( 'Settings have been saved.', 'wp-security-audit-log' ); ?></p>
358                                        </div>
359                                        <?php
360                                endif;
361                        } catch ( Exception $ex ) {
362                                ?>
363                                <div class="error">
364                                        <p><?php esc_html_e( 'Error: ', 'wp-security-audit-log' ); ?><?php echo esc_html( $ex->getMessage() ); ?></p>
365                                </div>
366                                <?php
367                        }
368                }
369
370                if ( isset( $_POST['import'] ) ) {
371                        call_user_func( $this->wsal_setting_tabs[ $this->current_tab ]['save'] );
372                }
373
374                if ( isset( $_GET['pruning'] ) && '1' === $_GET['pruning'] ) {
375                        ?>
376                        <div class="updated">
377                                <p><?php esc_html_e( 'Old data successfully purged.', 'wp-security-audit-log' ); ?></p>
378                        </div>
379                        <?php
380                } elseif ( isset( $_GET['pruning'] ) && '0' === $_GET['pruning'] ) {
381                        ?>
382                        <div class="error">
383                                <p><?php esc_html_e( 'No data is old enough to be purged.', 'wp-security-audit-log' ); ?></p>
384                        </div>
385                        <?php
386                }
387                ?>
388                <nav id="wsal-tabs" class="nav-tab-wrapper">
389                        <?php foreach ( $this->wsal_setting_tabs as $tab_id => $tab ) : ?>
390                                <a href="<?php echo esc_url( $tab['link'] ); ?>" class="nav-tab <?php echo ( $tab_id === $this->current_tab ) ? 'nav-tab-active' : false; ?>">
391                                        <?php echo esc_html( $tab['name'] ); ?>
392                                </a>
393                        <?php endforeach; ?>
394                </nav>
395
396                <form id="audit-log-settings" method="post">
397                        <input type="hidden" name="page" value="<?php echo isset( $_GET['page'] ) ? esc_attr( \sanitize_text_field( wp_unslash( $_GET['page'] ) ) ) : false; ?>" />
398                        <input type="hidden" id="ajaxurl" value="<?php echo esc_attr( admin_url( 'admin-ajax.php' ) ); ?>" />
399                        <?php wp_nonce_field( 'wsal-settings' ); ?>
400
401                        <div id="audit-log-adverts"></div>
402                        <div class="nav-tabs">
403                                <?php
404                                if ( ! empty( $this->current_tab ) && ! empty( $this->wsal_setting_tabs[ $this->current_tab ]['render'] ) ) {
405                                        call_user_func( $this->wsal_setting_tabs[ $this->current_tab ]['render'] );
406                                } else {
407                                        call_user_func( $this->wsal_setting_tabs['general']['render'] );
408                                }
409                                ?>
410                        </div>
411                        <?php
412                        if ( 'sms-provider' === $this->current_tab && $section && 'test' === $section ) {
413                                \submit_button( esc_html__( 'Send Message', 'wp-security-audit-log' ) );
414                        } elseif ( 'settings-export-import' !== $this->current_tab ) {
415                                        \submit_button();
416                        }
417                        ?>
418                </form>
419
420                <script>
421                        function delete_confirm(elementRef) {
422                                if (elementRef.checked) {
423                                        if ( window.confirm('<?php esc_html_e( 'Do you want to remove all data when the plugin is deleted?', 'wp-security-audit-log' ); ?>') == false ) {
424                                                elementRef.checked = false;
425                                                // Ensure the "no" option is reselected.
426                                                jQuery('#delete_data_no').click();
427                                        }
428                                }
429                        }
430
431                        jQuery( document ).ready( function() {
432                                // Enable/disable setting.
433                                function wsal_update_setting( checkbox, setting ) {
434                                        if ( checkbox.prop( 'checked' ) ) {
435                                                setting.removeProp( 'disabled' );
436                                        } else {
437                                                setting.prop( 'disabled', 'disabled' );
438                                        }
439                                }
440
441                                // Login page notification settings.
442                                var login_page_notif = jQuery( 'input[name=login_page_notification]' );
443                                var login_page_notif_text = jQuery( '#login_page_notification_text' );
444
445                                // Check the change event on checkbox.
446                                login_page_notif.on( 'change', function() {
447                                        wsal_update_setting( login_page_notif, login_page_notif_text );
448                                } );
449
450                                jQuery( 'input[name=EnableProxyIpCapture]' ).change( function() {
451                                       
452                                        if ( jQuery('#enable_proxy_ip_capture_custom').is(':checked') ) {
453                                                jQuery('#proxy_header_input').css("display", 'block');
454                                        } else {
455                                                jQuery('#proxy_header_input').css("display", 'none');
456                                        }
457
458                                        if ( jQuery('#enable_proxy_ip_capture_yes').is(':checked') ) {
459                                                jQuery('#proxy_custom_header').css("display", 'block');
460                                        } else {
461                                                jQuery('#proxy_custom_header').css("display", 'none');
462                                        }
463                                });
464
465                        } );
466                        </script>
467                <?php
468        }
469
470        /**
471         * Tab: `General`
472         */
473        private function tab_general() {
474                $enforced_settings                                   = Plugin_Settings_Helper::get_mainwp_enforced_settings();
475                $login_page_notification_settings_enforced_by_mainwp = array_key_exists( 'login_notification_enabled', $enforced_settings );
476                $incognito_setting_enforced_by_mainwp                = array_key_exists( 'incognito_mode_enabled', $enforced_settings );
477
478                ?>
479
480                <h3><?php esc_html_e( 'Display latest events widget in Dashboard & Admin bar', 'wp-security-audit-log' ); ?></h3>
481                <p class="description">
482                        <?php
483                        echo sprintf(
484                                /* translators: Max number of dashboard widget alerts. */
485                                esc_html__( 'The events widget displays the latest %d security events in the dashboard and the admin bar notification displays the latest event.', 'wp-security-audit-log' ),
486                                esc_html( Settings_Helper::DASHBOARD_WIDGET_MAX_ALERTS )
487                        );
488                        ?>
489                </p>
490                <table class="form-table wsal-tab">
491                        <tbody>
492                        <tr>
493                                <th><label for="dwoption_on"><?php esc_html_e( 'Dashboard widget', 'wp-security-audit-log' ); ?></label></th>
494                                <td>
495                                        <fieldset>
496                                                <?php $dwe = ! Settings_Helper::get_boolean_option_value( 'disable-widgets' ); ?>
497                                                <label for="dwoption_on">
498                                                        <input type="radio" name="EnableDashboardWidgets" id="dwoption_on" style="margin-top: -2px;" <?php checked( $dwe ); ?> value="1">
499                                                        <span><?php esc_html_e( 'Yes', 'wp-security-audit-log' ); ?></span>
500                                                </label>
501                                                <br/>
502                                                <label for="dwoption_off">
503                                                        <input type="radio" name="EnableDashboardWidgets" id="dwoption_off" style="margin-top: -2px;" <?php checked( $dwe, false ); ?>  value="0">
504                                                        <span><?php esc_html_e( 'No', 'wp-security-audit-log' ); ?></span>
505                                                </label>
506                                        </fieldset>
507                                </td>
508                        </tr>
509                        <!-- / Events Dashboard Widget -->
510
511                        <tr>
512                                <?php
513                                $disabled = '';
514                                $label    = esc_html__( 'Admin bar notification', 'wp-security-audit-log' );
515                                if ( wsal_freemius()->is_free_plan() ) {
516                                        $disabled = 'disabled';
517                                        $label    = esc_html__( 'Admin bar notification', 'wp-security-audit-log' );
518                                }
519                                ?>
520                                <th><label for="admin_bar_notif_on"><?php echo esc_html( $label ); ?></label></th>
521                                <td>
522                                        <fieldset <?php echo esc_attr( $disabled ); ?>>
523                                                <?php $abn = ! Settings_Helper::get_boolean_option_value( 'disable-admin-bar-notif', true ); ?>
524                                                <label for="admin_bar_notif_on">
525                                                        <input type="radio" name="admin_bar_notif" id="admin_bar_notif_on" style="margin-top: -2px;" <?php checked( $abn ); ?> value="1">
526                                                        <span><?php esc_html_e( 'Yes', 'wp-security-audit-log' ); ?></span>
527                                                </label>
528                                                <br/>
529                                                <label for="admin_bar_notif_off">
530                                                        <input type="radio" name="admin_bar_notif" id="admin_bar_notif_off" style="margin-top: -2px;" <?php checked( $abn, false ); ?>  value="0">
531                                                        <span><?php esc_html_e( 'No', 'wp-security-audit-log' ); ?></span>
532                                                </label>
533                                        </fieldset>
534                                </td>
535                        </tr>
536                        <!-- / Admin Bar Notification -->
537
538                        <tr>
539                                <?php
540                                $disabled = '';
541                                $label    = esc_html__( 'Admin bar notification updates', 'wp-security-audit-log' );
542                                if ( wsal_freemius()->is_free_plan() ) {
543                                        $disabled = 'disabled';
544                                        $label    = esc_html__( 'Admin bar notification updates', 'wp-security-audit-log' );
545                                }
546                                ?>
547                                <th><label for="admin_bar_notif_refresh"><?php echo esc_html( $label ); ?></label></th>
548                                <td>
549                                        <fieldset <?php echo esc_attr( $disabled ); ?>>
550                                                <?php $abn_updates = WSAL\Helpers\Settings_Helper::get_option_value( 'admin-bar-notif-updates', 'page-refresh' ); ?>
551                                                <label for="admin_bar_notif_realtime">
552                                                        <input type="radio" name="admin_bar_notif_updates" id="admin_bar_notif_realtime" style="margin-top: -2px;" <?php checked( $abn_updates, 'real-time' ); ?> value="real-time">
553                                                        <span><?php esc_html_e( 'Update in near real time', 'wp-security-audit-log' ); ?></span>
554                                                </label>
555                                                <br/>
556                                                <label for="admin_bar_notif_refresh">
557                                                        <input type="radio" name="admin_bar_notif_updates" id="admin_bar_notif_refresh" style="margin-top: -2px;" <?php checked( $abn_updates, 'page-refresh' ); ?>  value="page-refresh">
558                                                        <span><?php esc_html_e( 'Update only on page refreshes', 'wp-security-audit-log' ); ?></span>
559                                                </label>
560                                        </fieldset>
561                                </td>
562                        </tr>
563                        <!-- / Admin Bar Notification Updates -->
564                        </tbody>
565                </table>
566                <!-- Dashboard Widget -->
567
568                <h3><?php esc_html_e( 'Add user notification on the WordPress login page', 'wp-security-audit-log' ); ?></h3>
569                <p class="description"><?php esc_html_e( 'Many compliance regulations (such as the GDPR) require website administrators to tell the users of their website that all the changes they do when logged in are being logged.', 'wp-security-audit-log' ); ?></p>
570                <table class="form-table wsal-tab">
571                        <tbody>
572                        <tr>
573                                <th><label for="login_page_notification"><?php esc_html_e( 'Login page notification', 'wp-security-audit-log' ); ?></label></th>
574                                <td>
575                                        <fieldset <?php echo disabled( $login_page_notification_settings_enforced_by_mainwp ); ?>>
576                                                <?php
577                                                // Get login page notification checkbox.
578                                                $wsal_lpn = Settings_Helper::get_boolean_option_value( 'login_page_notification', false );
579                                                if ( $wsal_lpn && 'true' === $wsal_lpn ) {
580                                                        // If option exists, value is true then set to true.
581                                                        $wsal_lpn = true;
582                                                } elseif ( $wsal_lpn && 'false' === $wsal_lpn ) {
583                                                        // If option exists, value is false then set to false.
584                                                        $wsal_lpn = false;
585                                                } elseif ( ! $wsal_lpn ) {
586                                                        // Default option value.
587                                                        $wsal_lpn = false;
588                                                }
589                                                ?>
590                                                <label for="wsal_lpn_yes">
591                                                        <input type="radio" name="login_page_notification" id="wsal_lpn_yes" <?php checked( $wsal_lpn ); ?> value="true" />
592                                                        <?php esc_html_e( 'Yes', 'wp-security-audit-log' ); ?>
593                                                </label>
594                                                <br />
595                                                <?php
596                                                // Get login page notification text.
597                                                $wsal_lpn_text = WSAL\Helpers\Settings_Helper::get_option_value( 'login_page_notification_text', false );
598                                                if ( ! $wsal_lpn_text ) {
599                                                        $wsal_lpn_text = __( 'For security and auditing purposes, a record of all of your logged-in actions and changes within the WordPress dashboard will be recorded in an activity log with the <a href="https://melapress.com/?utm_source=plugin&utm_medium=referral&utm_campaign=wsal&utm_content=settings+pages" target="_blank">WP Activity Log plugin</a>. The audit log also includes the IP address where you accessed this site from.', 'wp-security-audit-log' );
600                                                }
601                                                // Allowed HTML tags for this setting.
602                                                $allowed_tags = array(
603                                                        'a' => array(
604                                                                'href'   => array(),
605                                                                'title'  => array(),
606                                                                'target' => array(),
607                                                        ),
608                                                );
609
610                                                ?>
611                                                <textarea name="login_page_notification_text"
612                                                                id="login_page_notification_text"
613                                                                cols="60" rows="6"
614                                                                <?php echo ( $wsal_lpn ) ? false : 'disabled'; ?>
615                                                        ><?php echo wp_kses( $wsal_lpn_text, $allowed_tags ); ?></textarea>
616                                                <br/>
617                                                <p class="description">
618                                                        <?php echo wp_kses( __( '<strong>Note: </strong>', 'wp-security-audit-log' ), Plugin_Settings_Helper::get_allowed_html_tags() ) . esc_html__( 'The only HTML code allowed in the login page notification is for links ( < a href >< /a > ).', 'wp-security-audit-log' ); // phpcs:ignore ?>
619                                                </p>
620                                                <br />
621
622                                                <label for="wsal_lpn_no">
623                                                        <input type="radio" name="login_page_notification" id="wsal_lpn_no" <?php checked( $wsal_lpn, false ); ?> value="false" />
624                                                        <?php esc_html_e( 'No', 'wp-security-audit-log' ); ?>
625                                                </label>
626                                        </fieldset>
627                                </td>
628                        </tr>
629                        <!-- / Login Page Notification -->
630                        </tbody>
631                </table>
632                <!-- Login Page Notification -->
633
634                <h3><?php esc_html_e( 'Is your website running behind a firewall or reverse proxy?', 'wp-security-audit-log' ); ?></h3>
635                <p class="description">
636                        <?php
637                        echo sprintf(
638                                /* translators: Learn more link. */
639                                esc_html__( 'If your website is running behind a web application firewall or reverse proxy, use the setting below to select the HTTP header the plugin should retrieve the end user IP from - %s.', 'wp-security-audit-log' ),
640                                '<a href="https://melapress.com/support/kb/wp-activity-log-support-reverse-proxies-web-application-firewalls/?utm_source=plugin&utm_medium=link&utm_campaign=wsal" target="_blank">' . esc_html__( 'learn more', 'wp-security-audit-log' ) . '</a>'
641                        );
642                        ?>
643                </p>
644                <table class="form-table wsal-tab">
645                        <tbody>
646                        <tr>
647                                <th><label for="pioption_on"><?php esc_html_e( 'Reverse proxy / firewall options', 'wp-security-audit-log' ); ?></label></th>
648                                <td>
649                                        <?php
650                                        if ( 2 === (int) Settings_Helper::get_option_value( 'use-proxy-ip' ) && '' === trim( Settings_Helper::get_option_value( 'proxy-custom-header', '' ) ) ) {
651                                                Settings_Helper::set_boolean_option_value( 'use-proxy-ip', false );
652                                        }
653                                        if ( 2 === (int) Settings_Helper::get_option_value( 'use-proxy-ip' ) ) {
654                                                $style = 'display: block;';
655                                        } else {
656                                                $style = 'display: none;';
657                                        }
658                                        ?>
659                                        <fieldset>
660                                                <label for="enable_proxy_ip_capture_yes">
661                                                        <input type="radio" name="EnableProxyIpCapture" value="1" id="enable_proxy_ip_capture_yes" <?php checked( Settings_Helper::get_boolean_option_value( 'use-proxy-ip' ) ); ?> />
662                                                <?php esc_html_e( 'Yes (select the HTTP header your proxy / firewall uses)', 'wp-security-audit-log' ); ?>
663                                                </label>
664                                                <div id="proxy_custom_header" style="margin-left: 30px;<?php echo ( ( Settings_Helper::get_boolean_option_value( 'use-proxy-ip', false ) ) ? '' : 'display:none;' ); ?>">
665                                                        <ul>
666                                                                <li>
667                                                                        <label for="REMOTE_ADDR">
668                                                                                <input type="radio" name="header-to-use" value="REMOTE_ADDR" id="REMOTE_ADDR" <?php checked( Settings_Helper::get_option_value( 'custom-header', 'REMOTE_ADDR' ), 'REMOTE_ADDR' ); ?>>REMOTE_ADDR
669                                                                        </label>
670                                                                </li>
671                                                                <li>
672                                                                        <label for="HTTP_CLIENT_IP">
673                                                                                <input type="radio" name="header-to-use" value="HTTP_CLIENT_IP" id="HTTP_CLIENT_IP" <?php checked( Settings_Helper::get_option_value( 'custom-header', 'REMOTE_ADDR' ), 'HTTP_CLIENT_IP' ); ?>>HTTP_CLIENT_IP
674                                                                        </label>
675                                                                </li>
676                                                                <li>
677                                                                        <label for="HTTP_X_FORWARDED_FOR">
678                                                                                <input type="radio" name="header-to-use" value="HTTP_X_FORWARDED_FOR" id="HTTP_X_FORWARDED_FOR" <?php checked( Settings_Helper::get_option_value( 'custom-header', 'REMOTE_ADDR' ), 'HTTP_X_FORWARDED_FOR' ); ?>>HTTP_X_FORWARDED_FOR
679                                                                        </label>
680                                                                </li>
681                                                                <li>
682                                                                        <label for="HTTP_X_FORWARDED">
683                                                                                <input type="radio" name="header-to-use" value="HTTP_X_FORWARDED" id="HTTP_X_FORWARDED" <?php checked( Settings_Helper::get_option_value( 'custom-header', 'REMOTE_ADDR' ), 'HTTP_X_FORWARDED' ); ?>>HTTP_X_FORWARDED
684                                                                        </label>
685                                                                </li>
686                                                                <li>
687                                                                        <label for="HTTP_X_CLUSTER_CLIENT_IP">
688                                                                                <input type="radio" name="header-to-use" value="HTTP_X_CLUSTER_CLIENT_IP" id="HTTP_X_CLUSTER_CLIENT_IP" <?php checked( Settings_Helper::get_option_value( 'custom-header', 'REMOTE_ADDR' ), 'HTTP_X_CLUSTER_CLIENT_IP' ); ?>>HTTP_X_CLUSTER_CLIENT_IP
689                                                                        </label>
690                                                                </li>
691                                                                <li>
692                                                                        <label for="X-ORIGINAL-FORWARDED-FOR">
693                                                                                <input type="radio" name="header-to-use" value="X-ORIGINAL-FORWARDED-FOR" id="X-ORIGINAL-FORWARDED-FOR" <?php checked( Settings_Helper::get_option_value( 'custom-header', 'REMOTE_ADDR' ), 'X-ORIGINAL-FORWARDED-FOR' ); ?>>X-ORIGINAL-FORWARDED-FOR
694                                                                        </label>
695                                                                </li>
696                                                                <li>
697                                                                        <label for="HTTP_FORWARDED_FOR">
698                                                                                <input type="radio" name="header-to-use" value="HTTP_FORWARDED_FOR" id="HTTP_FORWARDED_FOR" <?php checked( Settings_Helper::get_option_value( 'custom-header', 'REMOTE_ADDR' ), 'HTTP_FORWARDED_FOR' ); ?>>HTTP_FORWARDED_FOR
699                                                                        </label>
700                                                                </li>
701                                                                <li>
702                                                                        <label for="HTTP_FORWARDED">
703                                                                                <input type="radio" name="header-to-use" value="HTTP_FORWARDED" id="HTTP_FORWARDED" <?php checked( Settings_Helper::get_option_value( 'custom-header', 'REMOTE_ADDR' ), 'HTTP_FORWARDED' ); ?>>HTTP_FORWARDED
704                                                                        </label>
705                                                                </li>
706                                                                <li>
707                                                                        <label for="HTTP_CF-CONNECTING-IP">
708                                                                                <input type="radio" name="header-to-use" value="HTTP_CF-CONNECTING-IP" id="HTTP_CF-CONNECTING-IP" <?php checked( Settings_Helper::get_option_value( 'custom-header', 'REMOTE_ADDR' ), 'HTTP_CF-CONNECTING-IP' ); ?>>HTTP_CF-CONNECTING-IP
709                                                                        </label>
710                                                                </li>
711                                                                <li>
712                                                                        <label for="HTTP_CF_CONNECTING_IP">
713                                                                                <input type="radio" name="header-to-use" value="HTTP_CF_CONNECTING_IP" id="HTTP_CF_CONNECTING_IP" <?php checked( Settings_Helper::get_option_value( 'custom-header', 'REMOTE_ADDR' ), 'HTTP_CF_CONNECTING_IP' ); ?>>HTTP_CF_CONNECTING_IP
714                                                                        </label>
715                                                                </li>
716                                                                <li>
717                                                                        <label for="CF-CONNECTING-IP">
718                                                                                <input type="radio" name="header-to-use" value="CF-CONNECTING-IP" id="CF-CONNECTING-IP" <?php checked( Settings_Helper::get_option_value( 'custom-header', 'REMOTE_ADDR' ), 'CF-CONNECTING-IP' ); ?>>CF-CONNECTING-IP
719                                                                        </label>
720                                                                </li>
721                                                                <li>
722                                                                        <label for="CF_CONNECTING_IP">
723                                                                                <input type="radio" name="header-to-use" value="CF_CONNECTING_IP" id="CF_CONNECTING_IP" <?php checked( Settings_Helper::get_option_value( 'custom-header', 'REMOTE_ADDR' ), 'CF_CONNECTING_IP' ); ?>>CF_CONNECTING_IP
724                                                                        </label>
725                                                                </li>
726                                                                <li>
727                                                                        <label for="HTTP_TRUE_CLIENT_IP">
728                                                                                <input type="radio" name="header-to-use" value="HTTP_TRUE_CLIENT_IP" id="HTTP_TRUE_CLIENT_IP" <?php checked( Settings_Helper::get_option_value( 'custom-header', 'REMOTE_ADDR' ), 'HTTP_TRUE_CLIENT_IP' ); ?>>HTTP_TRUE_CLIENT_IP
729                                                                        </label>
730                                                                </li>
731                                                                <li>
732                                                                        <label for="TRUE_CLIENT_IP">
733                                                                                <input type="radio" name="header-to-use" value="TRUE_CLIENT_IP" id="TRUE_CLIENT_IP" <?php checked( Settings_Helper::get_option_value( 'custom-header', 'REMOTE_ADDR' ), 'TRUE_CLIENT_IP' ); ?>>TRUE_CLIENT_IP
734                                                                        </label>
735                                                                </li>
736                                                        </ul>
737                                                </div>
738                                                <br/>
739                                                <label for="enable_proxy_ip_capture_custom">
740                                                        <input type="radio" name="EnableProxyIpCapture" value="2" id="enable_proxy_ip_capture_custom" <?php checked( Settings_Helper::get_option_value( 'use-proxy-ip' ), 2 ); ?> />
741                                                        <?php esc_html_e( 'Custom (specify the name of the HTTP header)', 'wp-security-audit-log' ); ?>
742                                                </label>
743                                                <div id="proxy_header_input" style="margin-left: 30px;<?php echo \esc_attr( $style ); ?>">
744                                                        <label for="custom_proxy_header">
745                                                                <input id="custom_proxy_header" type="text" name="CustomProxyIpHeader" id="CustomProxyIpHeader" value="<?php echo Settings_Helper::get_option_value( 'proxy-custom-header' ); ?>"/>
746                                                        </label>
747                                                </div>
748                                                <br/>
749                                                <label for="enable_proxy_ip_capture_no">
750                                                        <input type="radio" name="EnableProxyIpCapture" value="0" id="enable_proxy_ip_capture_no" <?php checked( Settings_Helper::get_option_value( 'use-proxy-ip', 0 ), 0 ); ?> />
751                                                        <?php esc_html_e( 'No', 'wp-security-audit-log' ); ?>
752                                                </label>
753                                                <br />
754                                        </fieldset>
755                                </td>
756                        </tr>
757                        <!-- / Reverse Proxy / Firewall Options -->
758                        </tbody>
759                </table>
760                <!-- Reverse Proxy -->
761
762                <h3><?php esc_html_e( 'Who can change the plugin settings?', 'wp-security-audit-log' ); ?></h3>
763                <p class="description">
764                        <?php
765                        $allowed_tags = array(
766                                'a' => array(
767                                        'href'   => true,
768                                        'target' => true,
769                                ),
770                        );
771                        echo wp_kses(
772                                sprintf(
773                                        /* translators: Learn more link. */
774                                        esc_html__( 'By default only users with administrator role (single site) and super administrator role (multisite) can change the settings of the plugin. Though you can restrict the privileges to just your user - %s.', 'wp-security-audit-log' ),
775                                        '<a href="https://melapress.com/support/kb/wp-activity-log-managing-plugin-privileges/?utm_source=plugin&utm_medium=link&utm_campaign=wsal" target="_blank">' . __( 'learn more', 'wp-security-audit-log' ) . '</a>'
776                                ),
777                                $allowed_tags
778                        );
779                        $restrict_settings = Plugin_Settings_Helper::get_restrict_plugin_setting();
780                        ?>
781                </p>
782                <table class="form-table wsal-tab">
783                        <tbody>
784                        <tr>
785                                <th><label for="RestrictAdmins"><?php esc_html_e( 'Restrict plugin access', 'wp-security-audit-log' ); ?></label></th>
786                                <td>
787                                        <fieldset>
788                                                <label for="only_me">
789                                                        <input type="radio" name="restrict-plugin-settings" id="only_me" value="only_me" <?php checked( $restrict_settings, 'only_me' ); ?> />
790                                                        <?php esc_html_e( 'Only me', 'wp-security-audit-log' ); ?>
791                                                </label>
792                                                <br/>
793                                                <label for="only_admins">
794                                                        <input type="radio" name="restrict-plugin-settings" id="only_admins" value="only_admins" <?php checked( $restrict_settings, 'only_admins' ); ?> />
795                                                        <?php
796                                                        if ( WP_Helper::is_multisite() ) {
797                                                                esc_html_e( 'All superadmins', 'wp-security-audit-log' );
798                                                        } else {
799                                                                esc_html_e( 'All administrators', 'wp-security-audit-log' );
800                                                        }
801                                                        ?>
802                                                </label>
803                                                <br/>
804                                        </fieldset>
805                                </td>
806                        </tr>
807                        <!-- / Restrict Plugin Access -->
808                        </tbody>
809                </table>
810                <!-- Restrict Plugin Access -->
811
812                <h3><?php esc_html_e( 'Allow other users to view the activity log', 'wp-security-audit-log' ); ?></h3>
813                <p class="description">
814                        <?php
815                        $is_multisite = WP_Helper::is_multisite();
816                        if ( $is_multisite ) {
817                                $section_label = esc_html__( 'By default only super administrators and the child sites\' administrators can view the WordPress activity log. Though you can change this by using the setting below.', 'wp-security-audit-log' );
818                        } else {
819                                $section_label = esc_html__( 'You can specify the username of the user that you want to allow. If you want to add all the users with a specific role, you can also specify their role here.', 'wp-security-audit-log' );
820                        }
821
822                        echo wp_kses(
823                                $section_label . ' - <a href="https://melapress.com/support/kb/wp-activity-log-allow-users-read-access-activity-log/?utm_source=plugin&utm_medium=link&utm_campaign=wsal" target="_blank">' . __( 'learn more', 'wp-security-audit-log' ) . '</a>',
824                                $allowed_tags
825                        );
826                        ?>
827                </p>
828                <?php if ( $is_multisite ) : ?>
829                        <table class="form-table wsal-tab">
830                                <tbody>
831                                <tr>
832                                        <th><?php esc_html_e( 'Can view events', 'wp-security-audit-log' ); ?></th>
833                                        <td>
834                                                <fieldset>
835                                                        <?php
836                                                        $restrict_settings          = Plugin_Settings_Helper::get_restrict_log_viewer();
837                                                        $viewer_restriction_options = array(
838                                                                'only_me'          => __( 'Only me', 'wp-security-audit-log' ),
839                                                                'only_superadmins' => __( 'Super administators only', 'wp-security-audit-log' ),
840                                                                'only_admins'      => __( 'Super administators and site administrators', 'wp-security-audit-log' ),
841                                                        );
842                                                        ?>
843                                                        <?php foreach ( $viewer_restriction_options as $option => $label ) : ?>
844                                                                <label for="<?php esc_attr( 'log_viewer_' . $option ); ?>">
845                                                                        <?php $disabled = ( 'only_me' === $option && 'only_superadmins' === $restrict_settings ); ?>
846                                                                        <input type="radio" name="restrict-log-viewer" id="<?php esc_attr( 'log_viewer_' . $option ); ?>" value="<?php echo esc_attr( $option ); ?>" <?php checked( $restrict_settings, $option ); ?> <?php disabled( $disabled ); ?> />
847                                                                        <?php echo esc_html( $label ); ?>
848                                                                </label>
849                                                                <br/>
850                                                        <?php endforeach; ?>
851                                                </fieldset>
852                                        </td>
853                                </tr>
854                                </tbody>
855                        </table>
856                        <p class="description"><?php esc_html_e( 'To allow someone who does not have an admin role to view the activity log, specify them in the below setting.', 'wp-security-audit-log' ); ?></p>
857                <?php endif; ?>
858                <table class="form-table wsal-tab">
859                        <tbody>
860                                <tr>
861                                        <?php $row_label = $is_multisite ? esc_html__( 'Can also view events', 'wp-security-audit-log' ) : esc_html__( 'Can view events', 'wp-security-audit-log' ); ?>
862                                        <th><label for="ViewerQueryBox"><?php echo $row_label; // phpcs:ignore ?></label></th>
863                                        <td>
864                                                <fieldset>
865                                                        <label>
866                                                                <input type="text" id="ViewerQueryBox" style="width: 250px;">
867                                                                <input type="button" id="ViewerQueryAdd" class="button-primary" value="<?php esc_attr_e( 'Add', 'wp-security-audit-log' ); ?>">
868
869                                                                <p class="description">
870                                                                        <?php esc_html_e( 'Specify the username or the users which do not have an admin role but can also see the WordPress activity role. You can also specify roles.', 'wp-security-audit-log' ); ?>
871                                                                </p>
872                                                        </label>
873
874                                                        <div id="ViewerList">
875                                                                <?php
876                                                                foreach ( Plugin_Settings_Helper::get_allowed_plugin_viewers() as $item ) :
877                                                                        if ( User_Helper::get_current_user()->user_login === $item ) {
878                                                                                continue;
879                                                                        }
880                                                                        ?>
881                                                                        <span class="sectoken-<?php echo esc_attr( Plugin_Settings_Helper::get_token_type( $item ) ); ?>">
882                                                                        <input type="hidden" name="Viewers[]" value="<?php echo esc_attr( $item ); ?>"/>
883                                                                        <?php echo esc_html( $item ); ?>
884                                                                        <a href="javascript:;" title="<?php esc_attr_e( 'Remove', 'wp-security-audit-log' ); ?>">&times;</a>
885                                                                        </span>
886                                                                <?php endforeach; ?>
887                                                        </div>
888                                                </fieldset>
889                                        </td>
890                                </tr>
891                                <!-- / Can View Alerts -->
892                        </tbody>
893                </table>
894                <!-- Can View Events -->
895
896                <h3><?php esc_html_e( 'Which email address should the plugin use as a from address?', 'wp-security-audit-log' ); ?></h3>
897                <p class="description"><?php esc_html_e( 'By default when the plugin sends an email notification it uses the email address specified in this website’s general settings. Though you can change the email address and display name from this section.', 'wp-security-audit-log' ); ?></p>
898                <table class="form-table wsal-tab">
899                        <tbody>
900                                <tr>
901                                        <th><label for="FromEmail"><?php esc_html_e( 'From e-mail & name', 'wp-security-audit-log' ); ?></label></th>
902                                        <td>
903                                                <fieldset>
904                                                        <?php $use_email = Settings_Helper::get_option_value( 'use-email', 'default_email' ); ?>
905                                                        <label for="default_email">
906                                                                <input type="radio" name="use-email" id="default_email" value="default_email" <?php checked( $use_email, 'default_email' ); ?> />
907                                                                <?php esc_html_e( 'Use the email address from the WordPress general settings', 'wp-security-audit-log' ); ?>
908                                                        </label>
909                                                        <br>
910                                                        <label for="custom_email">
911                                                                <input type="radio" name="use-email" id="custom_email" value="custom_email" <?php checked( $use_email, 'custom_email' ); ?> />
912                                                                <?php esc_html_e( 'Use another email address', 'wp-security-audit-log' ); ?>
913                                                        </label>
914                                                        <br>
915                                                        <label for="FromEmail">
916                                                                <?php esc_html_e( 'Email Address', 'wp-security-audit-log' ); ?>
917                                                                <input type="email" id="FromEmail" name="FromEmail" value="<?php echo esc_attr( WSAL\Helpers\Settings_Helper::get_option_value( 'from-email' ) ); ?>" />
918                                                        </label>
919                                                        <br>
920                                                        <label for="DisplayName">
921                                                                <?php esc_html_e( 'Display Name', 'wp-security-audit-log' ); ?>&nbsp;
922                                                                <input type="text" id="DisplayName" name="DisplayName" value="<?php echo esc_attr( WSAL\Helpers\Settings_Helper::get_option_value( 'display-name' ) ); ?>" />
923                                                        </label>
924                                                </fieldset>
925                                        </td>
926                                </tr>
927                                <!-- / From Email & Name -->
928                        </tbody>
929                </table>
930                <!-- From Email & Name -->
931
932                <?php
933                $is_incognito = Settings_Helper::get_boolean_option_value( 'hide-plugin' );
934                ?>
935                <h3><?php esc_html_e( 'Do you want to hide the plugin from the list of installed plugins?', 'wp-security-audit-log' ); ?></h3>
936                <p class="description"><?php esc_html_e( 'By default all installed plugins are listed in the plugins page. Set this option to Yes remove WP Activity Log from the list of installed plugins for users who are unable to access the WP Activity Log settings.', 'wp-security-audit-log' ); ?></p>
937                <table class="form-table wsal-tab">
938                        <tbody>
939                                <tr>
940                                        <th><label for="incognito_yes"><?php esc_html_e( 'Hide plugin in plugins page', 'wp-security-audit-log' ); ?></label></th>
941                                        <td>
942                                                <fieldset <?php echo disabled( $incognito_setting_enforced_by_mainwp ); ?>>
943                                                        <label for="incognito_yes">
944                                                                <input type="radio" name="Incognito" value="yes" id="incognito_yes" <?php checked( $is_incognito ); ?> />
945                                                                <?php esc_html_e( 'Yes, hide the plugin from the list of installed plugins', 'wp-security-audit-log' ); ?>
946                                                        </label>
947                                                        <br/>
948                                                        <label for="incognito_no">
949                                                                <input type="radio" name="Incognito" value="no" id="incognito_no" <?php checked( $is_incognito, false ); ?> />
950                                                                <?php esc_html_e( 'No, do not hide the plugin', 'wp-security-audit-log' ); ?>
951                                                        </label>
952                                                </fieldset>
953                                        </td>
954                                </tr>
955                                <!-- / Hide Plugin in Plugins Page -->
956                        </tbody>
957                </table>
958                <!-- Hide Plugin -->
959                <?php
960        }
961
962        /**
963         * Save: `General`
964         */
965        private function tab_general_save() {
966                // Get $_POST global array.
967                $post_array = filter_input_array( INPUT_POST );
968
969                Settings_Helper::set_option_value( 'use-email', \sanitize_text_field( $post_array['use-email'] ) );
970                Settings_Helper::set_option_value( 'from-email', trim( \sanitize_email( $post_array['FromEmail'] ) ) );
971                Settings_Helper::set_option_value( 'display-name', trim( \sanitize_text_field( $post_array['DisplayName'] ) ) );
972                Settings_Helper::set_boolean_option_value( 'disable-widgets', ! \sanitize_text_field( $post_array['EnableDashboardWidgets'] ) );
973
974                if ( ! wsal_freemius()->is_free_plan() ) {
975                        Settings_Helper::set_boolean_option_value( 'disable-admin-bar-notif', ! \sanitize_text_field( $post_array['admin_bar_notif'] ), true );
976                        Settings_Helper::set_option_value( 'admin-bar-notif-updates', \sanitize_text_field( $post_array['admin_bar_notif_updates'] ), true );
977                }
978
979                // Handle log viewer settings in multisite context.
980                if ( WP_Helper::is_multisite() ) {
981                        $log_viewer_restrictions = isset( $post_array['restrict-log-viewer'] ) ? \sanitize_text_field( $post_array['restrict-log-viewer'] ) : '';
982                        Plugin_Settings_Helper::set_restrict_log_viewer( $log_viewer_restrictions );
983                        if ( 'only_me' === $log_viewer_restrictions ) {
984                                Plugin_Settings_Helper::set_only_me_user_id( \get_current_user_id() );
985                        }
986                }
987
988                // Get plugin viewers.
989                $viewers = isset( $post_array['Viewers'] ) ? array_map( 'sanitize_text_field', $post_array['Viewers'] ) : array();
990                Plugin_Settings_Helper::set_allowed_plugin_viewers( $viewers );
991
992                // Handle plugin settings permissions.
993                $restrict_settings = isset( $post_array['restrict-plugin-settings'] ) ? \sanitize_text_field( $post_array['restrict-plugin-settings'] ) : false;
994                Plugin_Settings_Helper::set_restrict_plugin_setting( $restrict_settings );
995                if ( 'only_me' === $restrict_settings ) {
996                        Plugin_Settings_Helper::set_only_me_user_id( get_current_user_id() );
997                }
998
999                Plugin_Settings_Helper::set_login_page_notification( isset( $post_array['login_page_notification'] ) ? \sanitize_text_field( $post_array['login_page_notification'] ) : false );
1000                Plugin_Settings_Helper::set_login_page_notification_text( isset( $post_array['login_page_notification_text'] ) ? $post_array['login_page_notification_text'] : false );
1001                Plugin_Settings_Helper::set_main_ip_from_proxy( isset( $post_array['EnableProxyIpCapture'] ) ? \sanitize_text_field( $post_array['EnableProxyIpCapture'] ) : false, ( isset( $post_array['header-to-use'] ) ? \sanitize_text_field( $post_array['header-to-use'] ) : 'REMOTE_ADDR' ), \sanitize_text_field( \wp_unslash( $post_array['CustomProxyIpHeader'] ) ) );
1002
1003                $is_incognito = isset( $post_array['Incognito'] ) ? Settings_Helper::string_to_bool( \sanitize_text_field( $post_array['Incognito'] ) ) : false;
1004                Plugin_Settings_Helper::set_incognito( $is_incognito );
1005        }
1006
1007        /**
1008         * Tab: `Audit Log`
1009         */
1010        private function tab_audit_log() {
1011                ?>
1012                <h3><?php esc_html_e( 'For how long do you want to keep the activity log events (Retention settings)?', 'wp-security-audit-log' ); ?></h3>
1013                <p class="description">
1014                        <?php
1015                        esc_html_e( 'The plugin uses an efficient way to store the activity log data in the WordPress database, though the more data you keep the more disk space will be required. ', 'wp-security-audit-log' );
1016                        $retention_help_text = __( '<a href="https://melapress.com/wordpress-activity-log/pricing/?utm_source=plugin&utm_medium=link&utm_campaign=wsal" target="_blank">Upgrade to Premium</a> to store the activity log data in an external database.', 'wp-security-audit-log' );
1017
1018                        // phpcs:disable
1019                        // phpcs:enable
1020                        echo wp_kses( $retention_help_text, Plugin_Settings_Helper::get_allowed_html_tags() );
1021                        ?>
1022                </p>
1023
1024                <?php
1025                // phpcs:disable
1026                /* @free:start */
1027                // phpcs:enable
1028                // Ensure it doesn't load a 2nd time for premium users.
1029                if ( ! wsal_freemius()->can_use_premium_code() ) {
1030                        $this->render_retention_settings_table();
1031                }
1032                // phpcs:disable
1033                /* @free:end */
1034                // phpcs:enable
1035                ?>
1036
1037                <h3><?php esc_html_e( 'What timestamp you would like to see in the WordPress activity log?', 'wp-security-audit-log' ); ?></h3>
1038                <p class="description"><?php esc_html_e( 'Note that the WordPress\' timezone might be different from that configured on the server so when you switch from UTC to WordPress timezone or vice versa you might notice a big difference.', 'wp-security-audit-log' ); ?></p>
1039                <table class="form-table wsal-tab">
1040                        <tbody>
1041                                <tr>
1042                                        <th><label for="timezone-default"><?php esc_html_e( 'Events timestamp', 'wp-security-audit-log' ); ?></label></th>
1043                                        <td>
1044                                                <fieldset>
1045                                                        <?php
1046                                                        $timezone = Settings_Helper::get_timezone();
1047
1048                                                        /**
1049                                                         * Transform timezone values.
1050                                                         *
1051                                                         * @since 3.2.3
1052                                                         */
1053                                                        if ( '0' === $timezone ) {
1054                                                                $timezone = 'utc';
1055                                                        } elseif ( '1' === $timezone ) {
1056                                                                $timezone = 'wp';
1057                                                        }
1058                                                        ?>
1059                                                        <label for="timezone-default">
1060                                                                <input type="radio" name="Timezone" id="timezone-default" style="margin-top: -2px;"
1061                                                                        <?php checked( $timezone, 'utc' ); ?> value="utc">
1062                                                                <?php esc_html_e( 'UTC', 'wp-security-audit-log' ); ?>
1063                                                        </label>
1064                                                        <br/>
1065                                                        <label for="timezone">
1066                                                                <input type="radio" name="Timezone" id="timezone" style="margin-top: -2px;"
1067                                                                        <?php checked( $timezone, 'wp' ); ?> value="wp">
1068                                                                <?php esc_html_e( 'Timezone configured on this WordPress website', 'wp-security-audit-log' ); ?>
1069                                                        </label>
1070                                                </fieldset>
1071                                        </td>
1072                                </tr>
1073                                <!-- Alerts Timestamp -->
1074                                <tr>
1075                                        <th><?php esc_html_e( 'Show milliseconds', 'wp-security-audit-log' ); ?></th>
1076                                        <td>
1077                                                <fieldset>
1078                                                        <?php $show_milliseconds = Settings_Helper::get_show_milliseconds(); ?>
1079                                                        <label for="show_milliseconds">
1080                                                                <input type="checkbox" name="show_milliseconds" id="show_milliseconds" style="margin-top: -2px;"
1081                                                                        <?php checked( $show_milliseconds ); ?> value="yes">
1082                                                                <?php esc_html_e( 'Show Milliseconds in list view', 'wp-security-audit-log' ); ?>
1083                                                        </label>
1084                                                </fieldset>
1085                                        </td>
1086                                </tr>
1087                                <!-- Alerts Timestamp -->
1088                        </tbody>
1089                </table>
1090                <!-- Timestamp -->
1091
1092                <h3><?php esc_html_e( 'What user information should be displayed in the WordPress activity log?', 'wp-security-audit-log' ); ?></h3>
1093                <p class="description"><?php esc_html_e( 'Usernames might not be the same as a user\'s first and last name so it can be difficult to recognize whose user was that did a change. When there is no first & last name or public display name configured the plugin will revert back to the WordPress username.', 'wp-security-audit-log' ); ?></p>
1094                <table class="form-table wsal-tab">
1095                        <tbody>
1096                                <tr>
1097                                        <th><label for="timezone-default"><?php esc_html_e( 'User information in activity log', 'wp-security-audit-log' ); ?></label></th>
1098                                        <td>
1099                                                <fieldset>
1100                                                        <?php $type_username = Plugin_Settings_Helper::get_type_username(); ?>
1101                                                        <label for="column_username">
1102                                                                <input type="radio" name="type_username" id="column_username" style="margin-top: -2px;" <?php checked( $type_username, 'username' ); ?> value="username">
1103                                                                <span><?php esc_html_e( 'WordPress username', 'wp-security-audit-log' ); ?></span>
1104                                                        </label>
1105                                                        <br/>
1106                                                        <label for="columns_first_last_name">
1107                                                                <input type="radio" name="type_username" id="columns_first_last_name" style="margin-top: -2px;" <?php checked( $type_username, 'first_last_name' ); ?> value="first_last_name">
1108                                                                <span><?php esc_html_e( 'First name & last name', 'wp-security-audit-log' ); ?></span>
1109                                                        </label>
1110                                                        <br/>
1111                                                        <label for="columns_display_name">
1112                                                                <input type="radio" name="type_username" id="columns_display_name" style="margin-top: -2px;" <?php checked( $type_username, 'display_name' ); ?> value="display_name">
1113                                                                <span><?php esc_html_e( 'Configured public display name', 'wp-security-audit-log' ); ?></span>
1114                                                        </label>
1115                                                </fieldset>
1116                                        </td>
1117                                </tr>
1118                                <!-- Select type of name -->
1119                        </tbody>
1120                </table>
1121                <!-- User Information -->
1122
1123                <?php $is_wp_backend = Settings_Helper::get_boolean_option_value( 'wp-backend' ); ?>
1124                <h3><?php esc_html_e( 'Do you want to keep a log of WordPress background activity?', 'wp-security-audit-log' ); ?></h3>
1125                <p class="description">
1126                        <?php esc_html_e( 'WordPress does a lot of things in the background that you do not necessarily need to know about, such as; deletion of post revisions, deletion of auto saved drafts etc. By default the plugin does not report them since there might be a lot and are irrelevant to the user.', 'wp-security-audit-log' ); ?>
1127                </p>
1128                <table class="form-table wsal-tab">
1129                        <tbody>
1130                                <tr>
1131                                        <th><label for="wp_backend_no"><?php esc_html_e( 'Enable events for WordPress background activity', 'wp-security-audit-log' ); ?></label></th>
1132                                        <td>
1133                                                <fieldset>
1134                                                        <label for="wp_backend_yes">
1135                                                                <input type="radio" name="WPBackend" value="1" id="wp_backend_yes" <?php checked( $is_wp_backend ); ?> />
1136                                                                <?php esc_html_e( 'Yes', 'wp-security-audit-log' ); ?>
1137                                                        </label>
1138                                                        <br/>
1139                                                        <label for="wp_backend_no">
1140                                                                <input type="radio" name="WPBackend" value="0" id="wp_backend_no" <?php checked( ! $is_wp_backend ); ?> />
1141                                                                <?php esc_html_e( 'No', 'wp-security-audit-log' ); ?>
1142                                                        </label>
1143                                                </fieldset>
1144                                        </td>
1145                                </tr>
1146                                <!-- Disable Alerts for WordPress Background activity -->
1147                        </tbody>
1148                </table>
1149                <!-- Background Events -->
1150                <?php
1151        }
1152
1153        /**
1154         * Save: `Audit Log`
1155         */
1156        private function tab_audit_log_save() {
1157                // Get $_POST global array.
1158                $post_array = filter_input_array( INPUT_POST );
1159
1160                // Get pruning date.
1161                $pruning_date = isset( $post_array['PruningDate'] ) ? (int) \sanitize_text_field( $post_array['PruningDate'] ) : false;
1162                $pruning_unit = isset( $post_array['pruning-unit'] ) ? \sanitize_text_field( $post_array['pruning-unit'] ) : false;
1163                $pruning_date = ( ! empty( $pruning_date ) && ! empty( $pruning_unit ) ) ? $pruning_date . ' ' . $pruning_unit : false;
1164
1165                $pruning_enabled = isset( $post_array['PruneBy'] ) ? 'date' === $post_array['PruneBy'] : '';
1166                Settings_Helper::set_pruning_date_settings( $pruning_enabled, $pruning_date, $pruning_unit );
1167                Plugin_Settings_Helper::set_timezone( $post_array['Timezone'] );
1168                Plugin_Settings_Helper::set_type_username( $post_array['type_username'] );
1169                Settings_Helper::set_boolean_option_value( 'wp-backend', isset( $post_array['WPBackend'] ) ? \sanitize_text_field( $post_array['WPBackend'] ) : false );
1170
1171                $show_milliseconds = isset( $post_array['show_milliseconds'] ) && 'yes' === $post_array['show_milliseconds'];
1172                Plugin_Settings_Helper::set_show_milliseconds( $show_milliseconds );
1173        }
1174
1175        /**
1176         * Tab: `File Changes`
1177         */
1178        private function tab_file_changes() {
1179                ?>
1180
1181                <table class="form-table wsal-tab">
1182                        <tbody>
1183                                <tr>
1184                                        <?php if ( ! defined( 'WFCM_PLUGIN_FILE' ) && ! defined( 'MFM_BASE_URL' ) ) : ?>
1185                                                <div class="addon-wrapper" style="max-width: 380px; text-align: center; border: 1px solid #ccc; padding: 25px;">
1186                                                        <img src="<?php echo esc_html( trailingslashit( WSAL_BASE_URL ) . 'img/help/website-file-changes-monitor.jpg' ); ?>">
1187                                                        <h4><?php echo esc_html__( 'Melapress File Monitor', 'wp-security-audit-log' ); ?></h4>
1188                                                        <p><?php echo esc_html__( 'To keep a log of file changes please install Melapress File Monitor, a plugin which is also developed by us.', 'wp-security-audit-log' ); ?></p><br>
1189                                                        <p><button class="install-addon button button-primary" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wsal-install-addon' ) ); ?>" data-plugin-slug="website-file-changes-monitor/website-file-changes-monitor.php" data-plugin-download-url="https://downloads.wordpress.org/plugin/website-file-changes-monitor.latest-stable.zip"><?php esc_html_e( 'Install plugin now', 'wp-security-audit-log' ); ?></button><span class="spinner" style="display: none; visibility: visible; float: none; margin: 0 0 0 8px;"></span> <a href="https://melapress.com/support/kb/wp-activity-log-wordpress-files-changes-warning-activity-logs/?utm_source=plugin&utm_medium=link&utm_campaign=wsal" rel="noopener noreferrer" target="_blank" style="margin-left: 15px;"><?php esc_html_e( 'Learn More', 'wp-security-audit-log' ); ?></a></p>
1190                                                </div>
1191                                        <?php else : ?>
1192                                                <?php
1193                                                $redirect_args = array(
1194                                                        'page' => 'file-monitor-settings',
1195                                                );
1196
1197                                                $wcfm_settings_page = add_query_arg( $redirect_args, \network_admin_url( 'admin.php' ) );
1198                                                ?>
1199                                                <p><?php echo esc_html__( 'Configure how often file changes scan run and other settings from the', 'wp-security-audit-log' ); ?> <a class="button button-primary" href="<?php echo esc_url( $wcfm_settings_page ); ?>"><?php echo esc_html__( 'Melapress File Monitor plugin settings', 'wp-security-audit-log' ); ?></a></p>
1200                                        <?php endif; ?>
1201                                </tr>
1202                        </tbody>
1203                </table>
1204                <style>
1205                        #submit {
1206                                display: none !important;
1207                        }
1208                </style>
1209                <!-- / File Changes Logging Tab -->
1210                <?php
1211        }
1212
1213        /**
1214         * Tab: `Exclude Objects`
1215         */
1216        private function tab_exclude_objects() {
1217                ?>
1218                <p class="description"><?php esc_html_e( 'By default the plugin keeps a log of all user changes done on your WordPress website. Use the setting below to exclude any objects from the activity log. When an object is excluded from the activity log, any event in which that object is referred will not be logged in the activity log.', 'wp-security-audit-log' ); ?></p>
1219                <table class="form-table wsal-tab">
1220                        <tbody>
1221                                <tr>
1222                                        <th><label for="ExUserQueryBox"><?php esc_html_e( 'Exclude users:', 'wp-security-audit-log' ); ?></label></th>
1223                                        <td>
1224                                                <fieldset>
1225                                                        <input type="text" id="ExUserQueryBox" style="width: 250px;">
1226                                                        <input type="button" id="ExUserQueryAdd" class="button-primary" value="<?php esc_attr_e( 'Add', 'wp-security-audit-log' ); ?>">
1227                                                        <br style="clear: both;"/>
1228                                                        <div id="ExUserList">
1229                                                                <?php foreach ( Settings_Helper::get_excluded_monitoring_users() as $item ) : ?>
1230                                                                        <span class="sectoken-<?php echo esc_attr( Plugin_Settings_Helper::get_token_type( $item ) ); ?>">
1231                                                                        <input type="hidden" name="ExUsers[]" value="<?php echo esc_attr( $item ); ?>"/>
1232                                                                        <?php echo esc_html( $item ); ?>
1233                                                                        <a href="javascript:;" title="<?php esc_attr_e( 'Remove', 'wp-security-audit-log' ); ?>">&times;</a>
1234                                                                        </span>
1235                                                                <?php endforeach; ?>
1236                                                        </div>
1237                                                </fieldset>
1238                                        </td>
1239                                </tr>
1240                                <!-- Exclude Users -->
1241
1242                                <tr>
1243                                        <th><label for="ExRoleQueryBox"><?php esc_html_e( 'Exclude roles:', 'wp-security-audit-log' ); ?></label></th>
1244                                        <td>
1245                                                <fieldset>
1246                                                        <input type="text" id="ExRoleQueryBox" style="width: 250px;">
1247                                                        <input type="button" id="ExRoleQueryAdd" class="button-primary" value="<?php esc_attr_e( 'Add', 'wp-security-audit-log' ); ?>">
1248                                                        <br style="clear: both;"/>
1249                                                        <div id="ExRoleList">
1250                                                                <?php foreach ( Settings_Helper::get_excluded_monitoring_roles() as $item ) : ?>
1251                                                                        <span class="sectoken-<?php echo esc_attr( Plugin_Settings_Helper::get_token_type( $item ) ); ?>">
1252                                                                        <input type="hidden" name="ExRoles[]" value="<?php echo esc_attr( $item ); ?>"/>
1253                                                                        <?php echo esc_html( $item ); ?>
1254                                                                        <a href="javascript:;" title="<?php esc_attr_e( 'Remove', 'wp-security-audit-log' ); ?>">&times;</a>
1255                                                                        </span>
1256                                                                <?php endforeach; ?>
1257                                                        </div>
1258                                                </fieldset>
1259                                        </td>
1260                                </tr>
1261                                <!-- Exclude Roles -->
1262
1263                                <tr>
1264                                        <th><label for="IpAddrQueryBox"><?php esc_html_e( 'Exclude IP address(es):', 'wp-security-audit-log' ); ?></label></th>
1265                                        <td>
1266                                                <fieldset>
1267                                                        <input type="text" id="IpAddrQueryBox" style="width: 250px;">
1268                                                        <input type="button" id="IpAddrQueryAdd" class="button-primary" value="<?php esc_attr_e( 'Add', 'wp-security-audit-log' ); ?>">
1269                                                        <br style="clear: both;"/>
1270                                                        <div id="IpAddrList">
1271                                                                <?php foreach ( Settings_Helper::get_excluded_monitoring_ips() as $item ) : ?>
1272                                                                        <span class="sectoken-<?php echo esc_attr( Plugin_Settings_Helper::get_token_type( $item ) ); ?>">
1273                                                                                <input type="hidden" name="IpAddrs[]" value="<?php echo esc_attr( $item ); ?>"/>
1274                                                                                <?php echo esc_html( $item ); ?>
1275                                                                                <a href="javascript:;" title="<?php esc_attr_e( 'Remove', 'wp-security-audit-log' ); ?>">&times;</a>
1276                                                                        </span>
1277                                                        <?php endforeach; ?>
1278                                                </div>
1279                                        </fieldset>
1280                                        <p class="description"><?php esc_html_e( 'You can exclude an individual IP address or a range of IP addresses. To exclude a range use the following format: [first IP]-[last octet of the last IP]. Example: 172.16.180.6-127.', 'wp-security-audit-log' ); ?></p>
1281                                </td>
1282                        </tr>
1283                        <!-- Exclude IP Addresses -->
1284
1285                        <tr>
1286                                <th><label for="ExCPTsQueryBox"><?php esc_html_e( 'Exclude post type:', 'wp-security-audit-log' ); ?></label></th>
1287                                <td>
1288                                        <fieldset>
1289                                                <input type="text" id="ExCPTsQueryBox" style="width: 250px;">
1290                                                <input type="button" id="ExCPTsQueryAdd" class="button-primary" value="<?php esc_attr_e( 'Add', 'wp-security-audit-log' ); ?>">
1291                                                <br style="clear: both;"/>
1292                                                <div id="ExCPTsList">
1293                                                        <?php foreach ( Settings_Helper::get_excluded_post_types() as $item ) : ?>
1294                                                                <span class="sectoken-<?php echo esc_attr( Plugin_Settings_Helper::get_token_type( $item ) ); ?>">
1295                                                                                <input type="hidden" name="ExCPTss[]" value="<?php echo esc_attr( $item ); ?>"/>
1296                                                                                <?php echo esc_html( $item ); ?>
1297                                                                                <a href="javascript:;" title="<?php esc_attr_e( 'Remove', 'wp-security-audit-log' ); ?>">&times;</a>
1298                                                                        </span>
1299                                                        <?php endforeach; ?>
1300                                                </div>
1301                                        </fieldset>
1302                                        <p class="description"><?php esc_html_e( 'WordPress has the post and page post types by default though your website might use more post types (custom post types). You can exclude all post types, including the default WordPress ones.', 'wp-security-audit-log' ); ?></p>
1303                                </td>
1304                        </tr>
1305                        <!-- Exclude Custom Post Types -->
1306
1307                        <tr>
1308                                <th><label for="StatusQueryBox"><?php esc_html_e( 'Exclude post status:', 'wp-security-audit-log' ); ?></label></th>
1309                                <td>
1310                                        <fieldset>
1311                                                <input type="text" id="StatusQueryBox" style="width: 250px;">
1312                                                <input type="button" id="StatusQueryAdd" class="button-primary" value="<?php esc_attr_e( 'Add', 'wp-security-audit-log' ); ?>">
1313                                                <br style="clear: both;"/>
1314                                                <div id="StatusList">
1315                                                        <?php foreach ( Settings_Helper::get_excluded_post_statuses() as $item ) : ?>
1316                                                                <span class="sectoken-<?php echo esc_attr( Plugin_Settings_Helper::get_token_type( $item ) ); ?>">
1317                                                                                <input type="hidden" name="Statuss[]" value="<?php echo esc_attr( $item ); ?>"/>
1318                                                                                <?php echo esc_html( $item ); ?>
1319                                                                                <a href="javascript:;" title="<?php esc_attr_e( 'Remove', 'wp-security-audit-log' ); ?>">&times;</a>
1320                                                                        </span>
1321                                                        <?php endforeach; ?>
1322                                                </div>
1323                                        </fieldset>
1324                                        <p class="description"><?php esc_html_e( 'You can exclude posts which have a specific Post Status from the activity logs by specifying the Post Status in this setting.', 'wp-security-audit-log' ); ?></p>
1325                                </td>
1326                        </tr>
1327                        <!-- Exclude Custom Post Status -->
1328
1329                                <?php
1330                                $this->renderMetaExclusionSection(
1331                                        esc_html__( 'Exclude custom post fields:', 'wp-security-audit-log' ),
1332                                        Settings_Helper::get_excluded_post_meta_fields(),
1333                                        'PostMeta'
1334                                );
1335                                ?>
1336                                <!-- Exclude Custom Post Fields -->
1337
1338                                <?php
1339                                $this->renderMetaExclusionSection(
1340                                        esc_html__( 'Exclude custom user fields:', 'wp-security-audit-log' ),
1341                                        Settings_Helper::get_excluded_user_meta_fields(),
1342                                        'UserMeta'
1343                                );
1344                                ?>
1345                                <!-- Exclude Custom User Fields -->
1346
1347                        </tbody>
1348                </table>
1349                <!-- / Exclude Objects Tab -->
1350                <?php
1351        }
1352
1353        /**
1354         * Renders form section for excluding metadata of certain object type.
1355         *
1356         * @param string $title  Section title.
1357         * @param array  $values Values.
1358         * @param string $type   Object type.
1359         */
1360        private function renderMetaExclusionSection( $title, $values, $type ) {
1361                ?>
1362                <tr>
1363                        <th><label for="Custom<?php echo \esc_attr( $type ); ?>QueryBox"><?php echo $title; ?></label></th>
1364                        <td>
1365                                <fieldset data-type="<?php echo \esc_attr( $type ); ?>">
1366                                        <input type="text" id="<?php echo \esc_attr( $type ); ?>QueryBox" class="js-query-box" style="width: 250px;">
1367                                        <input type="button" id="<?php echo \esc_attr( $type ); ?>QueryAdd" class="js-query-add button-primary"
1368                                                        value="<?php esc_attr_e( 'Add', 'wp-security-audit-log' ); ?>">
1369                                        <br style="clear: both;"/>
1370                                        <div id="<?php echo \esc_attr( $type ); ?>List" class="js-list">
1371                                                <?php foreach ( $values as $item ) : ?>
1372                                                        <span class="sectoken-<?php echo esc_attr( Plugin_Settings_Helper::get_token_type( $item ) ); ?>">
1373                                                                                <input type="hidden" name="<?php echo \esc_attr( $type ); ?>s[]"
1374                                                                                                value="<?php echo esc_attr( $item ); ?>"/>
1375                                                                                <?php echo esc_html( $item ); ?>
1376                                                                                <a href="javascript:;" title="<?php esc_attr_e( 'Remove', 'wp-security-audit-log' ); ?>">&times;</a>
1377                                                                        </span>
1378                                                <?php endforeach; ?>
1379                                        </div>
1380                                </fieldset>
1381                                <p class="description"><?php esc_html_e( 'You can use the * wildcard to exclude multiple matching custom fields. For example to exclude all custom fields starting with wp123 enter wp123*', 'wp-security-audit-log' ); ?></p>
1382                        </td>
1383                </tr>
1384                <?php
1385        }
1386
1387        /**
1388         * Save: `Exclude Objects`
1389         */
1390        private function tab_exclude_objects_save() {
1391                // Get $_POST global array.
1392                $post_array = filter_input_array( INPUT_POST );
1393
1394                Settings_Helper::set_excluded_monitoring_users( isset( $post_array['ExUsers'] ) ? $post_array['ExUsers'] : array() );
1395                Settings_Helper::set_excluded_monitoring_roles( isset( $post_array['ExRoles'] ) ? $post_array['ExRoles'] : array() );
1396                Settings_Helper::set_excluded_post_meta_fields( isset( $post_array['PostMetas'] ) ? $post_array['PostMetas'] : array() );
1397                Settings_Helper::set_excluded_user_meta_fields( isset( $post_array['UserMetas'] ) ? $post_array['UserMetas'] : array() );
1398                Plugin_Settings_Helper::set_excluded_monitoring_ip( isset( $post_array['IpAddrs'] ) ? $post_array['IpAddrs'] : array() );
1399                Plugin_Settings_Helper::set_excluded_post_types( isset( $post_array['ExCPTss'] ) ? $post_array['ExCPTss'] : array() );
1400                Plugin_Settings_Helper::set_excluded_post_statuses( isset( $post_array['Statuss'] ) ? $post_array['Statuss'] : array() );
1401        }
1402
1403        /**
1404         * Tab: `Advanced Settings`
1405         */
1406        private function tab_advanced_settings() {
1407                ?>
1408                <p class="description">
1409                        <?php esc_html_e( 'These settings are for advanced users.', 'wp-security-audit-log' ); ?>
1410                        <?php echo sprintf( __( 'If you have any questions <a href="https://melapress.com/contact/?utm_source=plugin&utm_medium=referral&utm_source=plugin&utm_medium=link&utm_campaign=wsal" target="_blank">contact us</a>.', 'wp-security-audit-log' ), Plugin_Settings_Helper::get_allowed_html_tags() ); // phpcs:ignore ?>
1411                </p>
1412
1413                <h3><?php esc_html_e( 'Reset plugin settings to default', 'wp-security-audit-log' ); ?></h3>
1414                <p class="description"><?php _e( 'Use this button to <em>factory reset</em> the plugin. This means that all the configured settings will be reset to default and all email notifications, scheduled reports, external database / third party services connections, archiving and mirroring rule will be deleted. NOTE: the activity log data will not be purged. Use the setting below to purge the activity log.', 'wp-security-audit-log' ); // phpcs:ignore ?></p>
1415                <table class="form-table wsal-tab">
1416                        <tbody>
1417                        <tr>
1418                                <th><?php esc_html_e( 'Reset Settings', 'wp-security-audit-log' ); ?></th>
1419                                <td>
1420                                        <a href="#wsal_reset_settings" class="button-primary js-settings-reset"><?php esc_html_e( 'RESET', 'wp-security-audit-log' ); ?></a>
1421                                </td>
1422                        </tr>
1423                        </tbody>
1424                </table>
1425
1426                <h3><?php esc_html_e( 'Purge the WordPress activity log', 'wp-security-audit-log' ); ?></h3>
1427                <p class="description"><?php esc_html_e( 'Click the Purge button below to delete all the data from the WordPress activity log and start afresh.', 'wp-security-audit-log' ); ?></p>
1428                <table class="form-table wsal-tab">
1429                        <tbody>
1430                                <tr>
1431                                        <th><?php esc_html_e( 'Purge Activity Log', 'wp-security-audit-log' ); ?></th>
1432                                        <td>
1433                                                <a href="#wsal_purge_activity" class="button-primary js-purge-reset"><?php esc_html_e( 'PURGE', 'wp-security-audit-log' ); ?></a>
1434                                                <!-- <span class="notice purge-notice notice-success" style="display: none; margin-left: 10px; padding: 6px 10px;"><?php esc_html_e( 'Activity log successfully purged', 'wp-security-audit-log' ); ?></span> -->
1435                                        </td>
1436                                </tr>
1437                        </tbody>
1438                </table>
1439
1440                <?php $stealth_mode = Settings_Helper::get_boolean_option_value( 'mwp-child-stealth-mode', false ); ?>
1441                <h3><?php esc_html_e( 'MainWP child site stealth mode', 'wp-security-audit-log' ); ?></h3>
1442                <p class="description"><?php esc_html_e( 'This option is enabled automatically when the plugin detects the MainWP Child plugin on the site. When this setting is enabled plugin access is restricted to the administrator who installs the plugin, the plugin is not shown in the list of installed plugins and no admin notifications are shown. Disable this option to change the plugin to the default setup.', 'wp-security-audit-log' ); ?></p>
1443                <table class="form-table wsal-tab">
1444                        <tbody>
1445                                <tr>
1446                                        <th><label for="mwp_stealth_mode"><?php esc_html_e( 'Enable MainWP child site stealth mode', 'wp-security-audit-log' ); ?></label></th>
1447                                        <td>
1448                                                <fieldset <?php echo ! WpSecurityAuditLog::is_mainwp_active() ? 'disabled' : false; ?>>
1449                                                        <label for="mwp_stealth_yes">
1450                                                                <input type="radio" name="mwp_stealth_mode" value="yes" id="mwp_stealth_yes" <?php checked( $stealth_mode ); ?> />
1451                                                                <?php esc_html_e( 'Yes', 'wp-security-audit-log' ); ?>
1452                                                        </label>
1453                                                        <br>
1454                                                        <label for="mwp_stealth_no">
1455                                                                <input type="radio" name="mwp_stealth_mode" value="no" id="mwp_stealth_no"
1456                                                                        <?php checked( $stealth_mode, false ); ?>
1457                                                                />
1458                                                                <?php esc_html_e( 'No', 'wp-security-audit-log' ); ?>
1459                                                        </label>
1460                                                </fieldset>
1461                                        </td>
1462                                </tr>
1463                        </tbody>
1464                </table>
1465
1466                <?php
1467                $data_deletion_enabled = Settings_Helper::get_boolean_option_value( 'delete-data' );
1468                ?>
1469                <h3><?php esc_html_e( 'Do you want to delete the plugin data from the database upon uninstall?', 'wp-security-audit-log' ); ?></h3>
1470                <p class="description"><?php esc_html_e( 'The plugin saves the activity log data and settings in the WordPress database. By default upon uninstalling the plugin the data is kept in the database so if it is installed again, you can still access the data. If the data is deleted it is not possible to recover it so you won\'t be able to access it again even when you reinstall the plugin.', 'wp-security-audit-log' ); ?></p>
1471                <table class="form-table wsal-tab">
1472                        <tbody>
1473                                <tr>
1474                                        <th><label for="DeleteData"><?php esc_html_e( 'Remove data on uninstall', 'wp-security-audit-log' ); ?></label></th>
1475                                        <td>
1476                                                <fieldset>
1477                                                        <label for="delete_data_yes">
1478                                                                <input type="radio" name="DeleteData" value="1" id="delete_data_yes" onclick="return delete_confirm(this);"
1479                                                                        <?php checked( $data_deletion_enabled ); ?>
1480                                                                />
1481                                                                <?php esc_html_e( 'Yes', 'wp-security-audit-log' ); ?>
1482                                                        </label>
1483                                                        <br>
1484                                                        <label for="delete_data_no">
1485                                                                <input type="radio" name="DeleteData" value="0" id="delete_data_no"
1486                                                                        <?php checked( $data_deletion_enabled, false ); ?>
1487                                                                />
1488                                                                <?php esc_html_e( 'No', 'wp-security-audit-log' ); ?>
1489                                                        </label>
1490                                                </fieldset>
1491                                        </td>
1492                                </tr>
1493                                <!-- / Remove Data on Uninstall -->
1494                        </tbody>
1495                </table>
1496
1497                <div class="remodal" data-remodal-id="wsal_reset_settings">
1498                        <button data-remodal-action="close" class="remodal-close"></button>
1499                        <h3><?php esc_html_e( 'Are you sure you want to reset all the plugin settings to default? This action cannot be undone.', 'wp-security-audit-log' ); ?></h3>
1500                        <br>
1501                        <input type="hidden" id="wsal-reset-settings-nonce" value="<?php echo esc_attr( wp_create_nonce( 'wsal-reset-settings' ) ); ?>">
1502                        <button data-remodal-action="confirm" class="remodal-confirm"><?php esc_html_e( 'Yes' ); ?></button>
1503                        <button data-remodal-action="cancel" class="remodal-cancel"><?php esc_html_e( 'No' ); ?></button>
1504                </div>
1505                <!-- Reset Settings Modal -->
1506
1507                <div class="remodal" data-remodal-id="wsal_purge_activity">
1508                        <button data-remodal-action="close" class="remodal-close"></button>
1509                        <h3><?php esc_html_e( 'Are you sure you want to purge all the activity log data?', 'wp-security-audit-log' ); ?></h3>
1510                        <br>
1511                        <input type="hidden" id="wsal-purge-activity-nonce" value="<?php echo esc_attr( wp_create_nonce( 'wsal-purge-activity' ) ); ?>">
1512                        <button data-remodal-action="confirm" class="remodal-confirm"><?php esc_html_e( 'Yes', 'wp-security-audit-log' ); ?></button>
1513                        <button data-remodal-action="cancel" class="remodal-cancel"><?php esc_html_e( 'No', 'wp-security-audit-log' ); ?></button>
1514                </div>
1515                <!-- Purge Activity Log Modal -->
1516                <?php
1517        }
1518
1519        /**
1520         * Save: `Advanced Settings`
1521         *
1522         * @throws Exception - MainWP Child plugin not active exception.
1523         */
1524        private function tab_advanced_settings_save() {
1525                // Get $_POST global array.
1526                $post_array = filter_input_array( INPUT_POST );
1527
1528                Plugin_Settings_Helper::set_delete_data( isset( $post_array['DeleteData'] ) ? \sanitize_text_field( $post_array['DeleteData'] ) : false );
1529
1530                $stealth_mode = isset( $post_array['mwp_stealth_mode'] ) ? $post_array['mwp_stealth_mode'] : false;
1531                if ( 'yes' === $stealth_mode ) {
1532                        if ( ! WpSecurityAuditLog::is_mainwp_active() ) {
1533                                throw new Exception( __( 'MainWP Child plugin is not active on this website.', 'wp-security-audit-log' ) );
1534                        }
1535                        Plugin_Settings_Helper::set_mainwp_child_stealth_mode();
1536
1537                } else {
1538                        Plugin_Settings_Helper::deactivate_mainwp_child_stealth_mode();
1539                }
1540        }
1541
1542        /**
1543         * {@inheritDoc}
1544         */
1545        public function header() {
1546                wp_enqueue_style(
1547                        'settings',
1548                        WSAL_BASE_URL . '/css/settings.css',
1549                        array(),
1550                        WSAL_VERSION
1551                );
1552
1553                // Check current tab.
1554                if ( ! empty( $this->current_tab ) && 'advanced-settings' === $this->current_tab ) {
1555                        // Remodal styles.
1556                        wp_enqueue_style( 'wsal-remodal', WSAL_BASE_URL . 'css/remodal.css', array(), WSAL_VERSION );
1557                        wp_enqueue_style( 'wsal-remodal-theme', WSAL_BASE_URL . 'css/remodal-default-theme.css', array(), WSAL_VERSION );
1558                }
1559                ?>
1560                <style type="text/css">
1561                        .wsal-tab {
1562                                /* display: none; */
1563                        }
1564                        .wsal-tab tr.alert-incomplete td {
1565                                color: #9BE;
1566                        }
1567                        .wsal-tab tr.alert-unavailable td {
1568                                color: #CCC;
1569                        }
1570                </style>
1571                <?php
1572        }
1573
1574        /**
1575         * {@inheritDoc}
1576         */
1577        public function footer() {
1578                wp_enqueue_script( 'jquery-ui-autocomplete' );
1579
1580                // Check current tab.
1581                if ( ! empty( $this->current_tab ) && 'advanced-settings' === $this->current_tab ) {
1582                        // Remodal script.
1583                        wp_enqueue_script(
1584                                'wsal-remodal-js',
1585                                WSAL_BASE_URL . 'js/remodal.min.js',
1586                                array(),
1587                                WSAL_VERSION,
1588                                true
1589                        );
1590                }
1591
1592                // Register settings script.
1593                wp_register_script(
1594                        'settings',
1595                        WSAL_BASE_URL . '/js/settings.js',
1596                        array(),
1597                        WSAL_VERSION,
1598                        true
1599                );
1600                // Passing nonce for security to JS file.
1601                $wsal_data = array(
1602                        'wp_nonce'            => wp_create_nonce( 'wsal-exclude-nonce' ),
1603                        'invalidURL'          => esc_html__( 'The specified value is not a valid URL!', 'wp-security-audit-log' ),
1604                        'invalidCPT'          => esc_html__( 'The specified value is not a valid post type!', 'wp-security-audit-log' ),
1605                        'invalidStatus'       => esc_html__( 'The specified value is not a valid post status!', 'wp-security-audit-log' ),
1606                        'invalidIP'           => esc_html__( 'The specified value is not a valid IP address!', 'wp-security-audit-log' ),
1607                        'invalidUser'         => esc_html__( 'The specified value is not a user nor a role!', 'wp-security-audit-log' ),
1608                        'invalidFile'         => esc_html__( 'Filename cannot be added because it contains invalid characters.', 'wp-security-audit-log' ),
1609                        'invalidFileExt'      => esc_html__( 'File extension cannot be added because it contains invalid characters.', 'wp-security-audit-log' ),
1610                        'invalidDir'          => esc_html__( 'Directory cannot be added because it contains invalid characters.', 'wp-security-audit-log' ),
1611                        'remove'              => esc_html__( 'Remove', 'wp-security-audit-log' ),
1612                        'saveSettingsChanges' => esc_html__( 'Please save any changes before switching tabs.', 'wp-security-audit-log' ),
1613                );
1614                wp_localize_script( 'settings', 'wsal_data', $wsal_data );
1615                wp_enqueue_script( 'settings' );
1616                ?>
1617                <script type="text/javascript">
1618                        jQuery( document ).ready( function() {
1619                                jQuery( '.sel-columns' ).change( function() {
1620                                        var notChecked = 1;
1621                                        jQuery( '.sel-columns' ).each( function() {
1622                                                if ( this.checked ) notChecked = 0;
1623                                        })
1624                                        if ( notChecked == 1 ) {
1625                                                alert( "<?php esc_html_e( 'You have to select at least one column!', 'wp-security-audit-log' ); ?>" );
1626                                        }
1627                                });
1628                                // jQuery( 'body' ).on( 'click', '.remodal-confirm', function ( e ) {
1629                                //      jQuery( '.purge-notice' ).fadeIn(500);
1630                                //      setTimeout(function() {
1631                                //              jQuery( '.purge-notice' ).fadeOut(500);
1632                                //      }, 4000);
1633                                // });
1634                        });</script>
1635                <?php
1636        }
1637
1638        /**
1639         * Method: Ajax Request handler for AjaxGetAllUsers.
1640         */
1641        public function ajax_get_all_users() {
1642                // Filter $_GET array for security.
1643                $get_array = filter_input_array( INPUT_GET );
1644                $this->check_ajax_request_is_valid( $get_array );
1645
1646                // Fetch users.
1647                $users = array();
1648                foreach ( get_users() as $user ) {
1649                        if ( strpos( $user->user_login, \sanitize_text_field( \wp_unslash( $get_array['term'] ) ) ) !== false ) {
1650                                array_push( $users, $user->user_login );
1651                        }
1652                }
1653                echo wp_json_encode( $users );
1654                exit;
1655        }
1656
1657        /**
1658         * Method: Ajax Request handler for AjaxGetAllRoles.
1659         */
1660        public function ajax_get_all_roles() {
1661                // Filter $_GET array for security.
1662                $get_array = filter_input_array( INPUT_GET );
1663                $this->check_ajax_request_is_valid( $get_array );
1664
1665                // Get roles.
1666                $roles = array();
1667                foreach ( get_editable_roles() as $role_name => $role_info ) {
1668                        if ( strpos( $role_name, \sanitize_text_field( \wp_unslash( $get_array['term'] ) )) !== false ) {
1669                                array_push( $roles, $role_name );
1670                        }
1671                }
1672                echo wp_json_encode( $roles );
1673                exit;
1674        }
1675
1676        /**
1677         * Create json array of all possible severities.
1678         *
1679         * @return void
1680         * @since  4.3.3
1681         */
1682        public function ajax_get_all_severities() {
1683                // Filter $_GET array for security.
1684                $get_array = filter_input_array( INPUT_GET );
1685                $this->check_ajax_request_is_valid( $get_array );
1686
1687                $result = array_map(
1688                        function ( $item ) {
1689                                return ucfirst( strtolower( str_replace( 'WSAL_', '', $item ) ) );
1690                        },
1691                        array_keys( Constants::get_severities() )
1692                );
1693
1694                echo $this->filter_values_for_searched_term( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1695                        $result,
1696                        \sanitize_text_field( \wp_unslash( $get_array['term'] ) )
1697                );
1698                exit;
1699        }
1700
1701        /**
1702         * Filters values to return ones matching the desired term.
1703         *
1704         * @param array  $items_to_filter List of items to filter.
1705         * @param string $term            Search term.
1706         *
1707         * @return string JSON encoded filtered list.
1708         */
1709        public function filter_values_for_searched_term( $items_to_filter, $term ) {
1710
1711                $result = array_filter(
1712                        $items_to_filter,
1713                        function( $value ) use ( $term ) {
1714                                return strpos( strtolower( $value ), strtolower( $term ) ) !== false;
1715                        }
1716                );
1717
1718                $result = array_map( 'strval', $result );
1719
1720                return wp_json_encode( $result );
1721        }
1722
1723        /**
1724         * Create json array of all possible event types.
1725         *
1726         * @return void
1727         * @since  4.3.3
1728         */
1729        public function ajax_get_all_event_types() {
1730                // Filter $_GET array for security.
1731                $get_array = filter_input_array( INPUT_GET );
1732                $this->check_ajax_request_is_valid( $get_array );
1733
1734                $event_types = Alert_Manager::get_event_type_data();
1735
1736                echo $this->filter_values_for_searched_term( array_values( $event_types ), \sanitize_text_field( \wp_unslash( $get_array['term'] ) ) );
1737                exit;
1738        }
1739
1740        /**
1741         * Create json array of all possible object types.
1742         *
1743         * @return void
1744         * @since  4.3.3
1745         */
1746        public function ajax_get_all_object_types() {
1747                // Filter $_GET array for security.
1748                $get_array = filter_input_array( INPUT_GET );
1749                $this->check_ajax_request_is_valid( $get_array );
1750
1751                $event_objects = Alert_Manager::get_event_objects_data();
1752
1753                echo $this->filter_values_for_searched_term( array_values( $event_objects ), \sanitize_text_field( \wp_unslash( $get_array['term'] ) ) ); // phpcs:ignore
1754                exit;
1755        }
1756
1757        /**
1758         * Create json array of all possible event IDs.
1759         *
1760         * @return void
1761         * @since  4.3.3
1762         */
1763        public function ajax_get_all_event_ids() {
1764
1765                $get_array = filter_input_array( INPUT_GET );
1766                $this->check_ajax_request_is_valid( $get_array );
1767
1768                $registered_alerts = Alert_Manager::get_alerts();
1769
1770                // $alerts = array();
1771                // foreach ( $registered_alerts as $alert => $details ) {
1772                // $alerts[] = (string) $details->code;
1773                // }
1774
1775                echo $this->filter_values_for_searched_term( array_keys( $registered_alerts ), \sanitize_text_field( \wp_unslash( $get_array['term'] ) ) );
1776                exit;
1777        }
1778
1779        /**
1780         * Method: Get CPTs ajax handle.
1781         *
1782         * @since 2.6.7
1783         */
1784        public function ajax_get_all_cpts() {
1785                // Filter $_GET array for security.
1786                $get_array = filter_input_array( INPUT_GET );
1787                $this->check_ajax_request_is_valid( $get_array );
1788
1789                // Get custom post types.
1790                $custom_post_types = array();
1791                $post_types        = get_post_types(
1792                        array(
1793                                'public' => false,
1794                        ),
1795                        'names'
1796                );
1797                // if we are running multisite and have networkwide cpt tracker get the
1798                // list from and merge to the post_types array.
1799                if ( WP_Helper::is_multisite() ) {
1800                        $network_cpts = WP_Helper::get_network_data_list();
1801                        foreach ( $network_cpts as $cpt ) {
1802                                $post_types[ $cpt ] = $cpt;
1803                        }
1804                }
1805
1806                $post_types = array_diff( $post_types, array( 'attachment', 'revision', 'nav_menu_item', 'customize_changeset', 'custom_css' ) );
1807                foreach ( $post_types as $post_type ) {
1808                        if ( strpos( $post_type, \sanitize_text_field( \wp_unslash( $get_array['term'] ) ) ) !== false ) {
1809                                array_push( $custom_post_types, $post_type );
1810                        }
1811                }
1812                echo wp_json_encode( $custom_post_types );
1813                exit;
1814        }
1815
1816        /**
1817         * Method: Get statuses ajax handle.
1818         *
1819         * @since 5.0.0
1820         */
1821        public function ajax_get_all_stati() {
1822                // Filter $_GET array for security.
1823                $get_array = filter_input_array( INPUT_GET );
1824                $this->check_ajax_request_is_valid( $get_array );
1825                $post_stati = get_post_stati();
1826
1827                echo wp_json_encode( $post_stati );
1828                exit;
1829        }
1830
1831        /**
1832         * Checks if provided GET array is valid and bails if not.
1833         *
1834         * @param array $get_array Get data.
1835         */
1836        public function check_ajax_request_is_valid( $get_array ) {
1837                // Die if user does not have permission to edit.
1838                if ( ! Settings_Helper::current_user_can( 'edit' ) ) {
1839                        die( 'Access Denied.' );
1840                }
1841
1842                // Die if nonce verification failed.
1843                if ( ! wp_verify_nonce( $get_array['wsal_nonce'], 'wsal-exclude-nonce' ) ) {
1844                        die( esc_html__( 'Nonce verification failed.', 'wp-security-audit-log' ) );
1845                }
1846        }
1847
1848        /**
1849         * Method: Reset plugin settings table.
1850         */
1851        public function reset_settings() {
1852                // Die if user does not have permission to change settings.
1853                if ( ! Settings_Helper::current_user_can( 'edit' ) ) {
1854                        wp_send_json_error( esc_html__( 'Access Denied.', 'wp-security-audit-log' ) );
1855                }
1856
1857                // Verify nonce.
1858                if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_POST['nonce'] ) ), 'wsal-reset-settings' ) ) {
1859                        wp_send_json_error( esc_html__( 'Nonce Verification Failed.', 'wp-security-audit-log' ) );
1860                }
1861
1862                // Delete all settings.
1863                Settings_Helper::delete_all_settings();
1864
1865                // Log settings reset event.
1866                Alert_Manager::trigger_event( 6006 );
1867                wp_send_json_success( esc_html__( 'Plugin settings have been reset.', 'wp-security-audit-log' ) );
1868        }
1869
1870        /**
1871         * Method: Purge plugin occurrence & meta tables.
1872         */
1873        public function purge_activity() {
1874                // Die if user does not have permission to change settings.
1875                if ( ! Settings_Helper::current_user_can( 'edit' ) ) {
1876                        wp_send_json_error( esc_html__( 'Access Denied.', 'wp-security-audit-log' ) );
1877                }
1878
1879                // Verify nonce.
1880                if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_POST['nonce'] ) ), 'wsal-purge-activity' ) ) {
1881                        wp_send_json_error( esc_html__( 'Nonce Verification Failed.', 'wp-security-audit-log' ) );
1882                }
1883
1884                $result = Database_Manager::purge_activity();
1885
1886                if ( $result ) {
1887                        // Log purge activity event.
1888                        Alert_Manager::trigger_event( 6034 );
1889                        wp_send_json_success( esc_html__( 'Tables has been reset.', 'wp-security-audit-log' ) );
1890                } else {
1891                        wp_send_json_error( esc_html__( 'Reset query failed.', 'wp-security-audit-log' ) );
1892                }
1893        }
1894
1895        /**
1896         * Renders table with retention related settings.
1897         */
1898        public function render_retention_settings_table() {
1899                // Check if the retention settings are enforced from the MainWP master site.
1900                $enforced_settings                     = Plugin_Settings_Helper::get_mainwp_enforced_settings();
1901                $retention_settings_enforced_by_mainwp = array_key_exists( 'pruning_enabled', $enforced_settings );
1902                ?>
1903                <table class="form-table wsal-tab">
1904                        <tbody>
1905                        <tr>
1906                                <th><label for="delete1"><?php esc_html_e( 'Activity log retention', 'wp-security-audit-log' ); ?></label></th>
1907                                <td>
1908                                        <fieldset>
1909                                                <?php $nbld = ! Settings_Helper::get_boolean_option_value( 'pruning-date-e' ); ?>
1910                                                <label for="delete0">
1911                                                        <input type="radio" id="delete0" name="PruneBy" value="" <?php checked( $nbld ); ?>
1912                                                                <?php disabled( $retention_settings_enforced_by_mainwp ); ?> />
1913                                                        <?php esc_html_e( 'Keep all data', 'wp-security-audit-log' ); ?>
1914                                                </label>
1915                                        </fieldset>
1916
1917                                        <fieldset>
1918                                                <?php
1919                                                // Check pruning date option.
1920                                                $nbld = Settings_Helper::get_boolean_option_value( 'pruning-date-e' );
1921
1922                                                // Find and replace ` months` in the string.
1923                                                $pruning_date = Plugin_Settings_Helper::get_pruning_date();
1924                                                $pruning_date = preg_replace( '/[^0-9]/', '', $pruning_date );
1925
1926                                                $pruning_unit = Plugin_Settings_Helper::get_pruning_unit();
1927
1928                                                $pruning_unit_options = array(
1929                                                        'days'   => esc_html__( 'Days', 'wp-security-audit-log' ),
1930                                                        'months' => esc_html__( 'Months', 'wp-security-audit-log' ),
1931                                                        'years'  => esc_html__( 'Years', 'wp-security-audit-log' ),
1932                                                );
1933
1934                                                // Check if pruning limit was enabled for backwards compatibility.
1935                                                if ( Settings_Helper::get_boolean_option_value( 'pruning-limit-e' ) ) {
1936                                                        $nbld         = true;
1937                                                        $pruning_date = '6';
1938                                                        $pruning_unit = 'months';
1939                                                        Settings_Helper::set_pruning_date_settings( true, $pruning_date . ' ' . $pruning_unit, $pruning_unit );
1940                                                        Plugin_Settings_Helper::set_pruning_limit_enabled( false );
1941                                                }
1942                                                ?>
1943                                                <label for="delete1">
1944                                                        <input type="radio" id="delete1" name="PruneBy" value="date" <?php checked( $nbld ); ?>
1945                                                                        <?php disabled( $retention_settings_enforced_by_mainwp ); ?> />
1946                                                        <?php esc_html_e( 'Delete events older than', 'wp-security-audit-log' ); ?>
1947                                                </label>
1948                                                <input type="number" id="PruningDate" name="PruningDate"
1949                                                        value="<?php echo esc_attr( $pruning_date ); ?>"
1950                                                        onfocus="jQuery('#delete1').attr('checked', true);"
1951                                                        <?php disabled( $retention_settings_enforced_by_mainwp ); ?>
1952                                                        min="1"
1953                                                />
1954                                                <select name="pruning-unit" id="pruning-unit" <?php disabled( $retention_settings_enforced_by_mainwp ); ?>>
1955                                                        <?php
1956                                                        foreach ( $pruning_unit_options as $option => $label ) {
1957                                                                echo '<option value="' . esc_attr( $option ) . '" ' . selected( $pruning_unit, $option, true ) . '>' . ucwords( $label ) . '</option>'; // phpcs:ignore
1958                                                        }
1959                                                        ?>
1960                                                </select>
1961                                        </fieldset>
1962
1963                                        <?php if ( Settings_Helper::get_boolean_option_value( 'pruning-date-e' ) ) : ?>
1964                                                <p class="description">
1965                                                        <?php
1966                                                        $next = (int) wp_next_scheduled( 'wsal_cleanup_hook' );
1967                                                        echo esc_html__( 'The next scheduled purging of activity log data that is older than ', 'wp-security-audit-log' );
1968                                                        echo esc_html( $pruning_date . ' ' . $pruning_unit );
1969                                                        echo sprintf(
1970                                                                ' is in %s.',
1971                                                                esc_html( human_time_diff( time(), $next ) )
1972                                                        );
1973                                                        echo '<!-- ' . esc_html( gmdate( 'dMy H:i:s', $next ) ) . ' --> ';
1974                                                        echo esc_html__( 'You can run the purging process now by clicking the button below.', 'wp-security-audit-log' );
1975                                                        ?>
1976                                                </p>
1977                                                <p>
1978                                                        <a class="button-primary" href="
1979                                                        <?php
1980                                                        echo esc_url(
1981                                                                add_query_arg(
1982                                                                        array(
1983                                                                                'action' => 'AjaxRunCleanup',
1984                                                                                'nonce'  => wp_create_nonce( 'wsal-run-cleanup' ),
1985                                                                        ),
1986                                                                        admin_url( 'admin-ajax.php' )
1987                                                                )
1988                                                        );
1989                                                        ?>
1990                                                        " data-nonce="<?php echo esc_attr( wp_create_nonce( 'wsal-run-cleanup' ) ); ?>" ><?php esc_html_e( 'Purge Old Data', 'wp-security-audit-log' ); ?></a>
1991                                                </p>
1992                                        <?php endif; ?>
1993                                </td>
1994                        </tr>
1995                        <!-- Activity log retention -->
1996                        </tbody>
1997                </table>
1998                <?php
1999        }
2000}
Note: See TracBrowser for help on using the repository browser.