PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.3
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.3
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / modules / logs / classes / class-log-settings.php

class-log-settings.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.3, at modules/logs/classes/class-log-settings.php

267 lines 13.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Centralized manager for WordPress backend functionality.
4 *
5 * @package MainWP\Dashboard
6 * @version 4.5.1
7 */
8
9 namespace MainWP\Dashboard\Module\Log;
10
11 use MainWP\Dashboard\MainWP_Utility;
12 use MainWP\Dashboard\MainWP_Settings_Indicator;
13
14 defined( 'ABSPATH' ) || exit;
15
16 /**
17 * Class - Log_Settings
18 */
19 class Log_Settings {
20
21 /**
22 * Holds Instance of manager object
23 *
24 * @var Log_manager
25 */
26 public $manager;
27
28 /**
29 * Holds settings values.
30 *
31 * @var options
32 */
33 public $options;
34
35 /**
36 * Current page.
37 *
38 * @static
39 * @var string $page Current page.
40 */
41 public static $page;
42
43
44 /**
45 * Class constructor.
46 *
47 * @param Log_Manager $manager Instance of manager object.
48 */
49 public function __construct( $manager ) {
50 $this->manager = $manager;
51
52 $this->options = get_option( 'mainwp_module_log_settings', array() );
53 if ( ! is_array( $this->options ) ) {
54 $this->options = array();
55 }
56 if ( ! isset( $this->options['enabled'] ) ) {
57 $this->options['enabled'] = 1;
58 MainWP_Utility::update_option( 'mainwp_module_log_settings', $this->options );
59 }
60
61 add_action( 'admin_init', array( $this, 'admin_init' ) );
62 add_filter( 'mainwp_getsubpages_settings', array( $this, 'add_subpage_menu_settings' ) );
63 add_filter( 'mainwp_init_primary_menu_items', array( $this, 'hook_init_primary_menu_items' ), 10, 2 );
64 }
65
66
67 /**
68 * Handle admin_init action.
69 */
70 public function admin_init() {
71 //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
72 if ( isset( $_POST['mainwp_module_log_settings_nonce'] ) && wp_verify_nonce( wp_unslash( $_POST['mainwp_module_log_settings_nonce'] ), 'logs_settings_nonce' ) ) {
73 $this->options['enabled'] = isset( $_POST['mainwp_module_log_enabled'] ) && ! empty( $_POST['mainwp_module_log_enabled'] ) ? 1 : 0;
74 $this->options['auto_purge'] = isset( $_POST['mainwp_module_log_enable_auto_purge'] ) && ! empty( $_POST['mainwp_module_log_enable_auto_purge'] ) ? 1 : 0;
75 $this->options['records_ttl'] = isset( $_POST['mainwp_module_log_records_ttl'] ) ? intval( $_POST['mainwp_module_log_records_ttl'] ) : 100;
76 MainWP_Utility::update_option( 'mainwp_module_log_settings', $this->options );
77 }
78 }
79
80 /**
81 * Init sub menu logs settings.
82 *
83 * @param array $subpages Sub pages.
84 *
85 * @action init
86 */
87 public function add_subpage_menu_settings( $subpages = array() ) {
88 $subpages[] = array(
89 'title' => esc_html__( 'Dashboard Insights', 'mainwp' ),
90 'slug' => 'Insights',
91 'callback' => array( $this, 'render_settings_page' ),
92 'class' => '',
93 );
94 return $subpages;
95 }
96
97 /**
98 * Init sub menu logs settings.
99 *
100 * @param array $items Sub menu items.
101 * @param string $which_menu first|second.
102 *
103 * @return array $tmp_items Menu items.
104 */
105 public function hook_init_primary_menu_items( $items, $which_menu ) {
106 if ( ! is_array( $items ) || 'first' !== $which_menu ) {
107 return $items;
108 }
109 $items[] = array(
110 'slug' => 'InsightsOverview',
111 'menu_level' => 2,
112 'menu_rights' => array(
113 'dashboard' => array(
114 'access_insights_dashboard',
115 ),
116 ),
117 'init_menu_callback' => array( static::class, 'init_menu' ),
118 'leftbar_order' => 2.9,
119 );
120 return $items;
121 }
122
123 /**
124 * Method init_menu()
125 *
126 * Add Insights Overview sub menu "Insights".
127 */
128 public static function init_menu() {
129
130 static::$page = add_submenu_page(
131 'mainwp_tab',
132 esc_html__( 'Insights', 'mainwp' ),
133 '<span id="mainwp-insights">' . esc_html__( 'Insights', 'mainwp' ) . '</span>',
134 'read',
135 'InsightsOverview',
136 array(
137 Log_Insights_Page::instance(),
138 'render_insights_overview',
139 )
140 );
141
142 Log_Insights_Page::init_left_menu();
143
144 if ( isset( $_GET['page'] ) && 'InsightsOverview' === $_GET['page'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
145 add_filter( 'mainwp_enqueue_script_gridster', '__return_true' );
146 }
147
148 add_action( 'load-' . static::$page, array( static::class, 'on_load_page' ) );
149 }
150
151 /**
152 * Method on_load_page()
153 *
154 * Run on page load.
155 */
156 public static function on_load_page() {
157 Log_Insights_Page::instance()->on_load_page( static::$page );
158 }
159
160 /**
161 * Render Insights settings page.
162 */
163 public function render_settings_page() {
164 /** This action is documented in ../pages/page-mainwp-manage-sites.php */
165 do_action( 'mainwp_pageheader_settings', 'Insights' );
166 $enabled = ! empty( $this->options['enabled'] ) ? true : false;
167
168 $enabled_auto_purge = isset( $this->options['auto_purge'] ) && ! empty( $this->options['auto_purge'] ) ? true : false;
169 ?>
170 <div id="mainwp-module-log-settings-wrapper" class="ui segment">
171 <div class="ui info message">
172 <div><?php esc_html_e( 'Dashboard Insights is a feature that will provide you with analytics data about your MainWP Dashboard usage. This version of the MainWP Dashboard contains only the logging part of this feature, which only logs actions performed in the MainWP Dashboard. Once the feature is fully completed, a new version will be released, and the logged data will be available.', 'mainwp' ); ?></div>
173 <div><?php esc_html_e( 'Important Note: Collected data stays on your server, and it will never be sent to MainWP servers or 3rd party. Logged data will only be used by you for informative purposes.', 'mainwp' ); ?></div>
174 </div>
175 <div class="ui form">
176 <form method="post" class="mainwp-table-container">
177 <div id="mainwp-message-zone" style="display:none;" class="ui message"></div>
178 <h3 class="ui dividing header">
179 <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-insights' ); ?>
180 <?php esc_html_e( 'Dashboard Insights Settings', 'mainwp' ); ?></h3>
181 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-insights" default-indi-value="1">
182 <label class="six wide column middle aligned">
183 <?php
184 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_module_log_enabled', (int) $enabled );
185 esc_html_e( 'Enable insights logging', 'mainwp' );
186 ?>
187 </label>
188 <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, your MainWP Dashboard will enable logging.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
189 <input type="checkbox" class="settings-field-value-change-handler" name="mainwp_module_log_enabled" id="mainwp_module_log_enabled" <?php echo $enabled ? 'checked="true"' : ''; ?> /><label><?php esc_html_e( 'Default: Enabled', 'mainwp' ); ?></label>
190 </div>
191 </div>
192 <?php $hide_field_class = 'log-settings-hidden-field'; ?>
193 <div class="ui grid field <?php echo esc_attr( $hide_field_class ); ?>">
194 <label class="six wide column middle aligned"><?php esc_html_e( 'Enable auto purge', 'mainwp' ); ?></label>
195 <div class="ten wide column ui toggle checkbox mainwp-checkbox-showhide-elements" hide-parent="auto-purge" data-tooltip="<?php esc_attr_e( 'If enabled, your MainWP Dashboard will auto purge logs.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
196 <input type="checkbox" name="mainwp_module_log_enable_auto_purge" id="mainwp_module_log_enable_auto_purge" <?php echo $enabled_auto_purge ? 'checked="true"' : ''; ?> /><label><?php esc_html_e( 'Default: Off', 'mainwp' ); ?></label>
197 </div>
198 </div>
199 <div class="ui grid field <?php echo esc_attr( $hide_field_class ); ?>" <?php echo $enabled ? '' : 'style="display:none"'; ?> hide-element="auto-purge">
200 <label class="six wide column middle aligned"><?php esc_html_e( 'Keep records for', 'mainwp' ); ?></label>
201 <div class="ten wide column ui" data-tooltip="<?php esc_attr_e( 'Maximum number of days to keep activity records.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
202 <input type="number" name="mainwp_module_log_records_ttl" id="mainwp_module_log_records_ttl" class="small-text" placeholder="" min="1" max="999" step="1" value="<?php echo isset( $this->options['records_ttl'] ) ? intval( $this->options['records_ttl'] ) : 100; ?>">
203 </div>
204 </div>
205 <h3 class="ui dividing header <?php echo esc_attr( $hide_field_class ); ?>"><?php esc_html_e( 'Dashboard Insights Tools', 'mainwp' ); ?></h3>
206 <div class="ui grid field <?php echo esc_attr( $hide_field_class ); ?>">
207 <label class="six wide column middle aligned"><?php esc_html_e( 'Delete records', 'mainwp' ); ?></label>
208 <div class="ten wide column ui">
209 <div class="three fields">
210 <div class="field">
211 <div class="ui calendar mainwp_datepicker" >
212 <div class="ui input left icon">
213 <i class="calendar icon"></i>
214 <input type="text" autocomplete="off" placeholder="<?php esc_attr_e( 'Start Date', 'mainwp' ); ?>" id="log_delete_records_startdate" value=""/>
215 </div>
216 </div>
217 </div>
218 <div class="field">
219 <div class="ui calendar mainwp_datepicker" >
220 <div class="ui input left icon">
221 <i class="calendar icon"></i>
222 <input type="text" autocomplete="off" placeholder="<?php esc_attr_e( 'End Date', 'mainwp' ); ?>" id="log_delete_records_enddate" value=""/>
223 </div>
224 </div>
225 </div>
226 <div class="field">
227 <input type="button" id="logs_delete_records_button" class="ui button" value="<?php esc_html_e( 'Delete', 'mainwp' ); ?>">
228 </div>
229 </div>
230 </div>
231 </div>
232
233 <div class="ui grid field <?php echo esc_attr( $hide_field_class ); ?>">
234 <label class="six wide column middle aligned"><?php esc_html_e( 'Compact insights data', 'mainwp' ); ?></label>
235 <div class="ten wide column ui">
236 <div class="ui selection dropdown" id="mainwp_module_log_compact_year" init-value="0">
237 <input name="mainwp_module_log_compact_year" value="0" type="hidden">
238 <i class="dropdown icon"></i>
239 <div class="default text"><?php esc_html_e( 'Select year', 'mainwp' ); ?></div>
240 <div class="menu">
241 <?php
242 $first = 2022;
243 $last = gmdate( 'Y' );
244 ?>
245 <?php
246 for ( $y = $last; $y >= $first; $y-- ) {
247 ?>
248 <div class="item" data-value="<?php echo intval( $y ); ?>"><?php echo esc_html( $y ); ?></div>
249 <?php } ?>
250 </div>
251 </div>
252 <input type="button" id="logs_compact_records_button" class="ui button" value="<?php esc_html_e( 'Compact', 'mainwp' ); ?>">
253 </div>
254 </div>
255 <div class="ui divider"></div>
256 <input type="submit" name="submit" id="submit" class="ui button green big" value="<?php esc_html_e( 'Save Settings', 'mainwp' ); ?>">
257 <input type="hidden" name="mainwp_module_log_settings_nonce" value="<?php echo esc_attr( wp_create_nonce( 'logs_settings_nonce' ) ); ?>">
258 </div>
259 </form>
260 </div>
261
262 <?php
263 /** This action is documented in ../pages/page-mainwp-manage-sites.php */
264 do_action( 'mainwp_pagefooter_settings', 'Insights' );
265 }
266 }
267