PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.0.3
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.0.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.0.3, at modules/logs/classes/class-log-settings.php

268 lines 11.0 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 $active = isset( $_GET['page'] ) && 'SettingsInsights' === $_GET['page'] ? true : false; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
89 $subpages[] = array(
90 'title' => esc_html__( 'Dashboard Insights', 'mainwp' ),
91 'slug' => 'Insights',
92 'callback' => array( $this, 'render_settings_page' ),
93 'class' => '',
94 );
95 return $subpages;
96 }
97
98 /**
99 * Init sub menu logs settings.
100 *
101 * @param array $items Sub menu items.
102 * @param string $which_menu first|second.
103 *
104 * @return array $tmp_items Menu items.
105 */
106 public function hook_init_primary_menu_items( $items, $which_menu ) {
107 if ( ! is_array( $items ) || 'first' !== $which_menu ) {
108 return $items;
109 }
110 $items[] = array(
111 'slug' => 'InsightsOverview',
112 'menu_level' => 2,
113 'menu_rights' => array(
114 'dashboard' => array(
115 'access_insights_dashboard',
116 ),
117 ),
118 'init_menu_callback' => array( self::class, 'init_menu' ),
119 'leftbar_order' => 2.9,
120 );
121 return $items;
122 }
123
124 /**
125 * Method init_menu()
126 *
127 * Add Insights Overview sub menu "Insights".
128 */
129 public static function init_menu() {
130
131 self::$page = add_submenu_page(
132 'mainwp_tab',
133 esc_html__( 'Insights', 'mainwp' ),
134 '<span id="mainwp-insights">' . esc_html__( 'Insights', 'mainwp' ) . '</span>',
135 'read',
136 'InsightsOverview',
137 array(
138 Log_Insights_Page::instance(),
139 'render_insights_overview',
140 )
141 );
142
143 Log_Insights_Page::init_left_menu();
144
145 if ( isset( $_GET['page'] ) && 'InsightsOverview' === $_GET['page'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
146 add_filter( 'mainwp_enqueue_script_gridster', '__return_true' );
147 }
148
149 add_action( 'load-' . self::$page, array( self::class, 'on_load_page' ) );
150 }
151
152 /**
153 * Method on_load_page()
154 *
155 * Run on page load.
156 */
157 public static function on_load_page() {
158 Log_Insights_Page::instance()->on_load_page( self::$page );
159 }
160
161 /**
162 * Render Insights settings page.
163 */
164 public function render_settings_page() {
165 /** This action is documented in ../pages/page-mainwp-manage-sites.php */
166 do_action( 'mainwp_pageheader_settings', 'Insights' );
167 $enabled = ! empty( $this->options['enabled'] ) ? true : false;
168
169 $enabled_auto_purge = isset( $this->options['auto_purge'] ) && ! empty( $this->options['auto_purge'] ) ? true : false;
170 ?>
171 <div id="mainwp-module-log-settings-wrapper" class="ui segment">
172 <div class="ui info message">
173 <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>
174 <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>
175 </div>
176 <div class="ui form">
177 <form method="post" class="mainwp-table-container">
178 <div id="mainwp-message-zone" style="display:none;" class="ui message"></div>
179 <h3 class="ui dividing header">
180 <?php echo MainWP_Settings_Indicator::get_indicator( 'header', 'settings-field-indicator-insights', 'insights-settings' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
181 <?php esc_html_e( 'Dashboard Insights Settings', 'mainwp' ); ?></h3>
182 <div class="ui grid field settings-field-indicator-insights">
183 <label class="six wide column middle aligned">
184 <?php
185 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_module_log_enabled', (int) $enabled );
186 esc_html_e( 'Enable insights logging', 'mainwp' );
187 ?>
188 </label>
189 <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">
190 <input type="checkbox" name="mainwp_module_log_enabled" id="mainwp_module_log_enabled" <?php echo ( $enabled ? 'checked="true"' : '' ); ?> /><label><?php esc_html_e( 'Default: Enabled', 'mainwp' ); ?></label>
191 </div>
192 </div>
193 <?php $hide_field_class = 'log-settings-hidden-field'; ?>
194 <div class="ui grid field <?php echo esc_attr( $hide_field_class ); ?>">
195 <label class="six wide column middle aligned"><?php esc_html_e( 'Enable auto purge', 'mainwp' ); ?></label>
196 <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">
197 <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>
198 </div>
199 </div>
200 <div class="ui grid field <?php echo esc_attr( $hide_field_class ); ?>" <?php echo $enabled ? '' : 'style="display:none"'; ?> hide-element="auto-purge">
201 <label class="six wide column middle aligned"><?php esc_html_e( 'Keep records for', 'mainwp' ); ?></label>
202 <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">
203 <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; ?>">
204 </div>
205 </div>
206 <h3 class="ui dividing header <?php echo esc_attr( $hide_field_class ); ?>"><?php esc_html_e( 'Dashboard Insights Tools', 'mainwp' ); ?></h3>
207 <div class="ui grid field <?php echo esc_attr( $hide_field_class ); ?>">
208 <label class="six wide column middle aligned"><?php esc_html_e( 'Delete records', 'mainwp' ); ?></label>
209 <div class="ten wide column ui">
210 <div class="three fields">
211 <div class="field">
212 <div class="ui calendar mainwp_datepicker" >
213 <div class="ui input left icon">
214 <i class="calendar icon"></i>
215 <input type="text" autocomplete="off" placeholder="<?php esc_attr_e( 'Start Date', 'mainwp' ); ?>" id="log_delete_records_startdate" value=""/>
216 </div>
217 </div>
218 </div>
219 <div class="field">
220 <div class="ui calendar mainwp_datepicker" >
221 <div class="ui input left icon">
222 <i class="calendar icon"></i>
223 <input type="text" autocomplete="off" placeholder="<?php esc_attr_e( 'End Date', 'mainwp' ); ?>" id="log_delete_records_enddate" value=""/>
224 </div>
225 </div>
226 </div>
227 <div class="field">
228 <input type="button" id="logs_delete_records_button" class="ui button" value="<?php esc_html_e( 'Delete', 'mainwp' ); ?>">
229 </div>
230 </div>
231 </div>
232 </div>
233
234 <div class="ui grid field <?php echo esc_attr( $hide_field_class ); ?>">
235 <label class="six wide column middle aligned"><?php esc_html_e( 'Compact insights data', 'mainwp' ); ?></label>
236 <div class="ten wide column ui">
237 <div class="ui selection dropdown" id="mainwp_module_log_compact_year" init-value="0">
238 <input name="mainwp_module_log_compact_year" value="0" type="hidden">
239 <i class="dropdown icon"></i>
240 <div class="default text"><?php esc_html_e( 'Select year', 'mainwp' ); ?></div>
241 <div class="menu">
242 <?php
243 $first = 2022;
244 $last = gmdate( 'Y' );
245 ?>
246 <?php
247 for ( $y = $last; $y >= $first; $y-- ) {
248 ?>
249 <div class="item" data-value="<?php echo intval( $y ); ?>"><?php echo esc_html( $y ); ?></div>
250 <?php } ?>
251 </div>
252 </div>
253 <input type="button" id="logs_compact_records_button" class="ui button" value="<?php esc_html_e( 'Compact', 'mainwp' ); ?>">
254 </div>
255 </div>
256 <div class="ui divider"></div>
257 <input type="submit" name="submit" id="submit" class="ui button green big" value="<?php esc_html_e( 'Save Settings', 'mainwp' ); ?>">
258 <input type="hidden" name="mainwp_module_log_settings_nonce" value="<?php echo esc_attr( wp_create_nonce( 'logs_settings_nonce' ) ); ?>">
259 </div>
260 </form>
261 </div>
262
263 <?php
264 /** This action is documented in ../pages/page-mainwp-manage-sites.php */
265 do_action( 'mainwp_pagefooter_settings', 'Insights' );
266 }
267 }
268