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

259 lines 10.4 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
13 defined( 'ABSPATH' ) || exit;
14
15 /**
16 * Class - Log_Settings
17 */
18 class Log_Settings {
19
20 /**
21 * Holds Instance of manager object
22 *
23 * @var Log_manager
24 */
25 public $manager;
26
27 /**
28 * Holds settings values.
29 *
30 * @var options
31 */
32 public $options;
33
34 /**
35 * Current page.
36 *
37 * @static
38 * @var string $page Current page.
39 */
40 public static $page;
41
42
43 /**
44 * Class constructor.
45 *
46 * @param Log_Manager $manager Instance of manager object.
47 */
48 public function __construct( $manager ) {
49 $this->manager = $manager;
50
51 $this->options = get_option( 'mainwp_module_log_settings', array() );
52 if ( ! is_array( $this->options ) ) {
53 $this->options = array();
54 }
55 if ( ! isset( $this->options['enabled'] ) ) {
56 $this->options['enabled'] = 1;
57 MainWP_Utility::update_option( 'mainwp_module_log_settings', $this->options );
58 }
59
60 add_action( 'admin_init', array( $this, 'admin_init' ) );
61 add_filter( 'mainwp_getsubpages_settings', array( $this, 'add_subpage_menu_settings' ) );
62 add_filter( 'mainwp_init_primary_menu_items', array( $this, 'hook_init_primary_menu_items' ), 10, 2 );
63 }
64
65
66 /**
67 * Handle admin_init action.
68 */
69 public function admin_init() {
70 //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
71 if ( isset( $_POST['mainwp_module_log_settings_nonce'] ) && wp_verify_nonce( wp_unslash( $_POST['mainwp_module_log_settings_nonce'] ), 'logs_settings_nonce' ) ) {
72 $this->options['enabled'] = isset( $_POST['mainwp_module_log_enabled'] ) && ! empty( $_POST['mainwp_module_log_enabled'] ) ? 1 : 0;
73 $this->options['auto_purge'] = isset( $_POST['mainwp_module_log_enable_auto_purge'] ) && ! empty( $_POST['mainwp_module_log_enable_auto_purge'] ) ? 1 : 0;
74 $this->options['records_ttl'] = isset( $_POST['mainwp_module_log_records_ttl'] ) ? intval( $_POST['mainwp_module_log_records_ttl'] ) : 100;
75 MainWP_Utility::update_option( 'mainwp_module_log_settings', $this->options );
76 }
77 }
78
79 /**
80 * Init sub menu logs settings.
81 *
82 * @param array $subpages Sub pages.
83 *
84 * @action init
85 */
86 public function add_subpage_menu_settings( $subpages = array() ) {
87 $subpages[] = array(
88 'title' => esc_html__( 'Dashboard Insights', 'mainwp' ),
89 'slug' => 'Insights',
90 'callback' => array( $this, 'render_settings_page' ),
91 'class' => '',
92 );
93 return $subpages;
94 }
95
96 /**
97 * Init sub menu logs settings.
98 *
99 * @param array $items Sub menu items.
100 * @param string $which_menu first|second.
101 *
102 * @return array $tmp_items Menu items.
103 */
104 public function hook_init_primary_menu_items( $items, $which_menu ) {
105 if ( ! is_array( $items ) || 'first' !== $which_menu ) {
106 return $items;
107 }
108 $items[] = array(
109 'slug' => 'InsightsOverview',
110 'menu_level' => 2,
111 'menu_rights' => array(
112 'dashboard' => array(
113 'access_insights_dashboard',
114 ),
115 ),
116 'init_menu_callback' => array( self::class, 'init_menu' ),
117 'leftbar_order' => 2.9,
118 );
119 return $items;
120 }
121
122 /**
123 * Method init_menu()
124 *
125 * Add Insights Overview sub menu "Insights".
126 */
127 public static function init_menu() {
128
129 self::$page = add_submenu_page(
130 'mainwp_tab',
131 esc_html__( 'Insights', 'mainwp' ),
132 '<span id="mainwp-insights">' . esc_html__( 'Insights', 'mainwp' ) . '</span>',
133 'read',
134 'InsightsOverview',
135 array(
136 Log_Insights_Page::instance(),
137 'render_insights_overview',
138 )
139 );
140
141 Log_Insights_Page::init_left_menu();
142
143 if ( isset( $_GET['page'] ) && 'InsightsOverview' === $_GET['page'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
144 add_filter( 'mainwp_enqueue_script_gridster', '__return_true' );
145 }
146
147 add_action( 'load-' . self::$page, array( self::class, 'on_load_page' ) );
148 }
149
150 /**
151 * Method on_load_page()
152 *
153 * Run on page load.
154 */
155 public static function on_load_page() {
156 Log_Insights_Page::instance()->on_load_page( self::$page );
157 }
158
159 /**
160 * Render Insights settings page.
161 */
162 public function render_settings_page() {
163 /** This action is documented in ../pages/page-mainwp-manage-sites.php */
164 do_action( 'mainwp_pageheader_settings', 'Insights' );
165 $enabled = ! empty( $this->options['enabled'] ) ? true : false;
166
167 $enabled_auto_purge = isset( $this->options['auto_purge'] ) && ! empty( $this->options['auto_purge'] ) ? true : false;
168 ?>
169 <div id="mainwp-module-log-settings-wrapper" class="ui segment">
170 <div class="ui info message">
171 <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>
172 <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>
173 </div>
174 <div class="ui form">
175 <form method="post" class="mainwp-table-container">
176 <div id="mainwp-message-zone" style="display:none;" class="ui message"></div>
177 <h3 class="ui dividing header"><?php esc_html_e( 'Dashboard Insights Settings', 'mainwp' ); ?></h3>
178 <div class="ui grid field">
179 <label class="six wide column middle aligned"><?php esc_html_e( 'Enable insights logging', 'mainwp' ); ?></label>
180 <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">
181 <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>
182 </div>
183 </div>
184 <?php $hide_field_class = 'log-settings-hidden-field'; ?>
185 <div class="ui grid field <?php echo esc_attr( $hide_field_class ); ?>">
186 <label class="six wide column middle aligned"><?php esc_html_e( 'Enable auto purge', 'mainwp' ); ?></label>
187 <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">
188 <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>
189 </div>
190 </div>
191 <div class="ui grid field <?php echo esc_attr( $hide_field_class ); ?>" <?php echo $enabled ? '' : 'style="display:none"'; ?> hide-element="auto-purge">
192 <label class="six wide column middle aligned"><?php esc_html_e( 'Keep records for', 'mainwp' ); ?></label>
193 <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">
194 <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; ?>">
195 </div>
196 </div>
197 <h3 class="ui dividing header <?php echo esc_attr( $hide_field_class ); ?>"><?php esc_html_e( 'Dashboard Insights Tools', 'mainwp' ); ?></h3>
198 <div class="ui grid field <?php echo esc_attr( $hide_field_class ); ?>">
199 <label class="six wide column middle aligned"><?php esc_html_e( 'Delete records', 'mainwp' ); ?></label>
200 <div class="ten wide column ui">
201 <div class="three fields">
202 <div class="field">
203 <div class="ui calendar mainwp_datepicker" >
204 <div class="ui input left icon">
205 <i class="calendar icon"></i>
206 <input type="text" autocomplete="off" placeholder="<?php esc_attr_e( 'Start Date', 'mainwp' ); ?>" id="log_delete_records_startdate" value=""/>
207 </div>
208 </div>
209 </div>
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( 'End Date', 'mainwp' ); ?>" id="log_delete_records_enddate" value=""/>
215 </div>
216 </div>
217 </div>
218 <div class="field">
219 <input type="button" id="logs_delete_records_button" class="ui button" value="<?php esc_html_e( 'Delete', 'mainwp' ); ?>">
220 </div>
221 </div>
222 </div>
223 </div>
224
225 <div class="ui grid field <?php echo esc_attr( $hide_field_class ); ?>">
226 <label class="six wide column middle aligned"><?php esc_html_e( 'Compact insights data', 'mainwp' ); ?></label>
227 <div class="ten wide column ui">
228 <div class="ui selection dropdown" id="mainwp_module_log_compact_year" init-value="0">
229 <input name="mainwp_module_log_compact_year" value="0" type="hidden">
230 <i class="dropdown icon"></i>
231 <div class="default text"><?php esc_html_e( 'Select year', 'mainwp' ); ?></div>
232 <div class="menu">
233 <?php
234 $first = 2022;
235 $last = gmdate( 'Y' );
236 ?>
237 <?php
238 for ( $y = $last; $y >= $first; $y-- ) {
239 ?>
240 <div class="item" data-value="<?php echo intval( $y ); ?>"><?php echo esc_html( $y ); ?></div>
241 <?php } ?>
242 </div>
243 </div>
244 <input type="button" id="logs_compact_records_button" class="ui button" value="<?php esc_html_e( 'Compact', 'mainwp' ); ?>">
245 </div>
246 </div>
247 <div class="ui divider"></div>
248 <input type="submit" name="submit" id="submit" class="ui button green big" value="<?php esc_html_e( 'Save Settings', 'mainwp' ); ?>">
249 <input type="hidden" name="mainwp_module_log_settings_nonce" value="<?php echo esc_attr( wp_create_nonce( 'logs_settings_nonce' ) ); ?>">
250 </div>
251 </form>
252 </div>
253
254 <?php
255 /** This action is documented in ../pages/page-mainwp-manage-sites.php */
256 do_action( 'mainwp_pagefooter_settings', 'Insights' );
257 }
258 }
259