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

954 lines 42.2 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;
13 use MainWP\Dashboard\MainWP_Settings_Indicator;
14
15 defined( 'ABSPATH' ) || exit;
16
17 /**
18 * Class - Log_Settings
19 */
20 class Log_Settings {
21
22 /**
23 * Holds Instance of manager object
24 *
25 * @var Log_manager
26 */
27 public $manager;
28
29 /**
30 * Holds settings values.
31 *
32 * @var options
33 */
34 public $options;
35
36 /**
37 * Current page.
38 *
39 * @static
40 * @var string $page Current page.
41 */
42 public static $page;
43
44 /**
45 * Store enable logs items settings.
46 *
47 * @static
48 * @var array $enable_logs_items Enabled logs items.
49 */
50 private static $enable_logs_items;
51
52 /**
53 * Class constructor.
54 *
55 * @param Log_Manager $manager Instance of manager object.
56 */
57 public function __construct( $manager ) {
58 $this->manager = $manager;
59
60 $this->load_settings();
61
62 add_action( 'admin_init', array( $this, 'admin_init' ) );
63 add_filter( 'mainwp_getsubpages_settings', array( $this, 'add_subpage_menu_settings' ) );
64 add_filter( 'mainwp_init_primary_menu_items', array( $this, 'hook_init_primary_menu_items' ), 10, 2 );
65 }
66
67
68 /**
69 * Handle admin_init action.
70 */
71 public function admin_init() { // phpcs:ignore -- NOSONAR - complex.
72 //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
73 if ( isset( $_POST['mainwp_module_log_settings_nonce'] ) && wp_verify_nonce( wp_unslash( $_POST['mainwp_module_log_settings_nonce'] ), 'logs_settings_nonce' ) ) {
74
75 $old_settings = MainWP_Settings::get_all_settings_values();
76
77 $old_enable = is_array( $this->options ) && ! empty( $this->options['enabled'] ) && ! empty( $this->options['auto_archive'] ) ? true : false;
78
79 $this->options['enabled'] = isset( $_POST['mainwp_module_log_enabled'] ) && ! empty( $_POST['mainwp_module_log_enabled'] ) ? 1 : 0;
80 $this->options['records_logs_ttl'] = isset( $_POST['mainwp_module_log_records_ttl'] ) ? intval( $_POST['mainwp_module_log_records_ttl'] ) : 3 * YEAR_IN_SECONDS;
81 $this->options['child_logs_ttl'] = isset( $_POST['mainwp_module_log_child_activities_ttl'] ) ? intval( $_POST['mainwp_module_log_child_activities_ttl'] ) : 7;
82 $this->options['auto_archive'] = isset( $_POST['mainwp_module_log_enable_auto_archive'] ) && ! empty( $_POST['mainwp_module_log_enable_auto_archive'] ) ? 1 : 0;
83 MainWP_Utility::update_option( 'mainwp_module_log_settings', $this->options );
84
85 $new_enable = is_array( $this->options ) && ! empty( $this->options['enabled'] ) && ! empty( $this->options['auto_archive'] ) ? true : false;
86
87 if ( $old_enable !== $new_enable ) {
88 // To reset.
89 $sched = wp_next_scheduled( 'mainwp_module_log_cron_job_auto_archive' );
90 if ( false !== $sched ) {
91 wp_unschedule_event( $sched, 'mainwp_module_log_cron_job_auto_archive' );
92 }
93 }
94
95 $logs_data = array(
96 'dashboard' => array(),
97 'nonmainwpchanges' => array(),
98 'changeslogs' => array(),
99 );
100
101 if ( isset( $_POST['mainwp_settings_logs_data'] ) && is_array( $_POST['mainwp_settings_logs_data'] ) ) {
102 $selected_data = $_POST['mainwp_settings_logs_data']; //phpcs:ignore -- NOSONAR -ok.
103 foreach ( array( 'dashboard', 'nonmainwpchanges', 'changeslogs' ) as $type ) {
104 $selected_type = isset( $selected_data[ $type ] ) && is_array( $selected_data[ $type ] ) ? array_map( 'sanitize_text_field', wp_unslash( $selected_data[ $type ] ) ) : array();
105 foreach ( $selected_type as $name ) {
106 $logs_data[ $type ][ $name ] = 1;
107 }
108 }
109 }
110
111 if ( isset( $_POST['mainwp_settings_logs_name'] ) && is_array( $_POST['mainwp_settings_logs_name'] ) ) {
112 $name_data = $_POST['mainwp_settings_logs_name']; //phpcs:ignore -- NOSONAR -ok.
113 foreach ( array( 'dashboard', 'nonmainwpchanges', 'changeslogs' ) as $type ) {
114 $name_type = isset( $name_data[ $type ] ) && is_array( $name_data[ $type ] ) ? array_map( 'sanitize_text_field', wp_unslash( $name_data[ $type ] ) ) : array();
115 foreach ( $name_type as $name ) {
116 if ( ! isset( $logs_data[ $type ][ $name ] ) ) {
117 $logs_data[ $type ][ $name ] = 0;
118 }
119 }
120 }
121 }
122 MainWP_Utility::update_option( 'mainwp_module_log_settings_logs_selection_data', wp_json_encode( $logs_data ) );
123
124 $new_settings = MainWP_Settings::get_all_settings_values();
125
126 /**
127 * Action: mainwp_after_save_settings
128 *
129 * Fires after save settings.
130 *
131 * @since 6.0
132 *
133 * @param array $new_settings The new settings.
134 * @param array $old_settings The old settings.
135 */
136 do_action( 'mainwp_after_save_settings', $new_settings, $old_settings );
137
138 }
139 }
140
141 /**
142 * Init sub menu logs settings.
143 *
144 * @param array $subpages Sub pages.
145 *
146 * @action init
147 */
148 public function add_subpage_menu_settings( $subpages = array() ) {
149 $subpages[] = array(
150 'title' => esc_html__( 'Network Activity Settings', 'mainwp' ),
151 'slug' => 'Insights',
152 'callback' => array( $this, 'render_settings_page' ),
153 'class' => '',
154 );
155 return $subpages;
156 }
157
158 /**
159 * Init sub menu logs settings.
160 *
161 * @param array $items Sub menu items.
162 * @param string $which_menu first|second.
163 *
164 * @return array $tmp_items Menu items.
165 */
166 public function hook_init_primary_menu_items( $items, $which_menu ) {
167 if ( ! is_array( $items ) || 'first' !== $which_menu ) {
168 return $items;
169 }
170 $items[] = array(
171 'slug' => 'InsightsOverview',
172 'menu_level' => 2,
173 'menu_rights' => array(
174 'dashboard' => array(
175 'access_insights_dashboard',
176 ),
177 ),
178 'init_menu_callback' => array( static::class, 'init_menu' ),
179 'leftbar_order' => 2.9,
180 );
181 return $items;
182 }
183
184 /**
185 * Method init_menu()
186 *
187 * Add Insights Operations sub menu "Insights".
188 */
189 public static function init_menu() {
190
191 static::$page = add_submenu_page(
192 'mainwp_tab',
193 esc_html__( 'Insights', 'mainwp' ),
194 '<span id="mainwp-insights">' . esc_html__( 'Insights', 'mainwp' ) . '</span>',
195 'read',
196 'InsightsOverview',
197 array(
198 Log_Insights_Page::instance(),
199 'render_insights_overview',
200 )
201 );
202
203 Log_Insights_Page::init_left_menu();
204
205 if ( isset( $_GET['page'] ) && 'InsightsOverview' === $_GET['page'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
206 add_filter( 'mainwp_enqueue_script_gridster', '__return_true' );
207 }
208
209 add_action( 'load-' . static::$page, array( static::class, 'on_load_page' ) );
210 }
211
212 /**
213 * Method load_settings().
214 */
215 public function load_settings() {
216 if ( null === $this->options ) {
217 $this->options = get_option( 'mainwp_module_log_settings', array() );
218 if ( ! is_array( $this->options ) ) {
219 $this->options = array();
220 }
221
222 $update = false;
223
224 if ( ! isset( $this->options['enabled'] ) ) {
225 $this->options['enabled'] = 1;
226 $update = true;
227 }
228 if ( ! isset( $this->options['records_logs_ttl'] ) ) {
229 $this->options['records_logs_ttl'] = 3 * YEAR_IN_SECONDS;
230 $update = true;
231 }
232
233 if ( $update ) {
234 MainWP_Utility::update_option( 'mainwp_module_log_settings', $this->options );
235 }
236 }
237 }
238
239 /**
240 * Method get_settings().
241 */
242 public function get_settings() {
243 return $this->options;
244 }
245
246 /**
247 * Method on_load_page()
248 *
249 * Run on page load.
250 */
251 public static function on_load_page() {
252 Log_Insights_Page::instance()->on_load_page( static::$page );
253 }
254
255 /**
256 * Render Insights settings page.
257 */
258 public function render_settings_page() { // phpcs:ignore -- NOSONAR - complex method.
259 /** This action is documented in ../pages/page-mainwp-manage-sites.php */
260 do_action( 'mainwp_pageheader_settings', 'Insights' );
261 $enabled = ! empty( $this->options['enabled'] ) ? true : false;
262 $enabled_auto_archive = isset( $this->options['auto_archive'] ) && ! empty( $this->options['auto_archive'] ) ? true : false;
263
264 $child_logs_ttl = isset( $this->options['child_logs_ttl'] ) ? $this->options['child_logs_ttl'] : 7;
265
266 ?>
267 <div id="mainwp-module-log-settings-wrapper" class="ui padded segment">
268 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-network-activity-settings-info-message' ) ) : ?>
269 <div class="ui info message">
270 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-network-activity-settings-info-message"></i>
271 <div class="ui header"><?php esc_html_e( 'Network Activity and Insights Data Logging', 'mainwp' ); ?></div>
272 <p><?php esc_html_e( 'The Network Activity system records actions performed through your MainWP Dashboard or directly on your child sites. This data powers both the Network Activity feature which displays a detailed timeline of changes and events and Dashboard Insights, which summarizes the same information to help you analyze usage trends and overall activity.', 'mainwp' ); ?></p>
273 <p><?php esc_html_e( 'All collected data is stored locally on your server. It is never sent to MainWP servers or shared with any third parties.', 'mainwp' ); ?></p>
274 </div>
275 <?php else : ?>
276 <div class="ui info message">
277 <div><?php esc_html_e( 'All collected data is stored locally on your server. It is never sent to MainWP servers or shared with any third parties.', 'mainwp' ); ?></div>
278 </div>
279 <?php endif; ?>
280 <div class="ui form">
281 <form method="post" class="mainwp-table-container">
282 <div id="mainwp-message-zone" style="display:none;" class="ui message"></div>
283 <h3 class="ui dividing header">
284 <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-insights' ); ?>
285 <?php esc_html_e( 'Dashboard Insights Settings', 'mainwp' ); ?>
286 <div class="sub header"><?php esc_html_e( 'Manage how MainWP records, stores, and displays Dashboard activity data used by Network Activity and Insights.', 'mainwp' ); ?></div>
287 </h3>
288 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-insights" default-indi-value="1">
289 <label class="six wide column middle aligned">
290 <?php
291 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_module_log_enabled', (int) $enabled );
292 esc_html_e( 'Enable Network Activity logging', 'mainwp' );
293 ?>
294 </label>
295 <div class="ten wide column ui toggle checkbox mainwp-checkbox-showhide-elements" hide-parent="auto-archive;child-logs-ttl">
296 <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></label>
297 </div>
298 </div>
299 <div class="ui grid field" id="field-log-enable-auto-archive">
300 <label class="six wide column middle aligned"><?php esc_html_e( 'Automatically archive logs', 'mainwp' ); ?></label>
301 <div class="ten wide column ui toggle checkbox mainwp-checkbox-showhide-elements" hide-parent="auto-archive" data-tooltip="<?php esc_attr_e( 'Automatically move older logs to the archive after a specified period of time. This helps keep your active logs organized while maintaining a searchable history.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
302 <input type="checkbox" name="mainwp_module_log_enable_auto_archive" id="mainwp_module_log_enable_auto_archive" <?php echo $enabled_auto_archive ? 'checked="true"' : ''; ?> /><label></label>
303 </div>
304 </div>
305 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-general" <?php echo ( $enabled && $enabled_auto_archive ) ? '' : 'style="display:none"'; ?> hide-element="auto-archive" default-indi-value="<?php echo (int) 3 * YEAR_IN_SECONDS; ?>">
306 <label class="six wide column middle aligned">
307 <?php
308 $records_ttl = $this->options['records_logs_ttl'];
309 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_module_log_records_ttl', $records_ttl, true, 3 * YEAR_IN_SECONDS );
310 esc_html_e( 'Data retention period', 'mainwp' );
311 ?>
312 </label>
313 <div class="ten wide column" data-tooltip="<?php esc_attr_e( 'Define how long logs should remain active before being automatically moved to the archive.', 'mainwp' ); ?>" data-inverted="" data-position="top left" >
314 <select name="mainwp_module_log_records_ttl" id="mainwp_module_log_records_ttl" class="ui dropdown settings-field-value-change-handler">
315 <option value="<?php echo (int) MONTH_IN_SECONDS; ?>" <?php echo (int) MONTH_IN_SECONDS === (int) $records_ttl ? 'selected' : ''; ?>><?php esc_html_e( 'One month', 'mainwp' ); ?></option>
316 <option value="<?php echo (int) 2 * MONTH_IN_SECONDS; ?>" <?php echo 2 * MONTH_IN_SECONDS === (int) $records_ttl ? 'selected' : ''; ?>><?php esc_html_e( 'Two months', 'mainwp' ); ?></option>
317 <option value="<?php echo (int) 3 * MONTH_IN_SECONDS; ?>" <?php echo 3 * MONTH_IN_SECONDS === (int) $records_ttl ? 'selected' : ''; ?>><?php esc_html_e( 'Three months', 'mainwp' ); ?></option>
318 <option value="<?php echo (int) 6 * MONTH_IN_SECONDS; ?>" <?php echo 6 * MONTH_IN_SECONDS === (int) $records_ttl ? 'selected' : ''; ?>><?php esc_html_e( 'Half a year', 'mainwp' ); ?></option>
319 <option value="<?php echo (int) YEAR_IN_SECONDS; ?>" <?php echo (int) YEAR_IN_SECONDS === (int) $records_ttl ? 'selected' : ''; ?>><?php esc_html_e( 'Year', 'mainwp' ); ?></option>
320 <option value="<?php echo (int) 2 * YEAR_IN_SECONDS; ?>" <?php echo 2 * YEAR_IN_SECONDS === (int) $records_ttl ? 'selected' : ''; ?>><?php esc_html_e( 'Two years', 'mainwp' ); ?></option>
321 <option value="<?php echo (int) 3 * YEAR_IN_SECONDS; ?>" <?php echo 3 * YEAR_IN_SECONDS === (int) $records_ttl ? 'selected' : ''; ?>><?php esc_html_e( 'Three years', 'mainwp' ); ?></option>
322 <option value="0" <?php echo 0 === (int) $records_ttl ? 'selected' : ''; ?>><?php esc_html_e( 'Forever', 'mainwp' ); ?></option>
323 </select>
324 </div>
325 </div>
326 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-insights" <?php echo ( $enabled ) ? '' : 'style="display:none"'; ?> hide-element="child-logs-ttl" default-indi-value="7">
327 <label class="six wide column middle aligned">
328 <?php
329 MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_module_log_child_activities_ttl', (int) get_option( 'mainwp_module_log_child_activities_ttl', 7 ) );
330 esc_html_e( 'Retention period for Network Activity Logs on child sites', 'mainwp' );
331 ?>
332 </label>
333 <div class="five wide column" data-tooltip="<?php esc_attr_e( 'Controls how long network activity logs are stored on child sites before local cleanup. This does not affect log retention on the Dashboard.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
334 <input type="number" class="settings-field-value-change-handler small-text" name="mainwp_module_log_child_activities_ttl" id="mainwp_module_log_child_activities_ttl" placeholder="" min="1" max="9999" step="1" value="<?php echo intval( $child_logs_ttl ); ?>">
335 </div>
336 </div>
337
338 <?php
339 static::render_logs_data_selection();
340 ?>
341 <div class="ui divider"></div>
342 <input type="submit" name="submit" id="submit" class="ui button green big" value="<?php esc_html_e( 'Save Settings', 'mainwp' ); ?>">
343 <input type="hidden" name="mainwp_module_log_settings_nonce" value="<?php echo esc_attr( wp_create_nonce( 'logs_settings_nonce' ) ); ?>">
344 </div>
345 </form>
346 </div>
347
348 <?php
349 /** This action is documented in ../pages/page-mainwp-manage-sites.php */
350 do_action( 'mainwp_pagefooter_settings', 'Insights' );
351 }
352
353
354 /**
355 * Method load_actions_logs_selection_settings().
356 *
357 * @return array Enable logs types.
358 */
359 public static function load_actions_logs_selection_settings() {
360 if ( null === static::$enable_logs_items ) {
361 $enable_logs = get_option( 'mainwp_module_log_settings_logs_selection_data' );
362
363 if ( ! empty( $enable_logs ) ) {
364 static::$enable_logs_items = json_decode( $enable_logs, true );
365 }
366
367 if ( ! is_array( static::$enable_logs_items ) ) {
368 static::$enable_logs_items = array();
369 }
370
371 $default_disabled_changeslogs = array_fill_keys(
372 static::get_disabled_changes_logs_default_settings(),
373 0
374 );
375
376 static::$enable_logs_items['changeslogs'] = array_replace(
377 $default_disabled_changeslogs,
378 static::$enable_logs_items['changeslogs'] ?? array()
379 );
380
381 }
382 return static::$enable_logs_items;
383 }
384
385 /**
386 * Method get_disabled_changes_logs_default_settings().
387 *
388 * @return array Disalbed default.
389 */
390 public static function get_disabled_changes_logs_default_settings() {
391 return array( 1310, 1315, 1680, 1925, 1930, 1935, 1940, 1945, 1950, 1955 );
392 }
393
394 /**
395 * Method is_action_log_enabled().
396 *
397 * @param string $name Log item name.
398 * @param string $type Log type dashboard|nonmainwpchanges.
399 *
400 * @return bool Enable log or not.
401 */
402 public static function is_action_log_enabled( $name, $type = 'dashboard' ) {
403
404 if ( ! in_array( $type, array( 'dashboard', 'nonmainwpchanges', 'changeslogs' ) ) ) {
405 return true;
406 }
407
408 static::load_actions_logs_selection_settings();
409
410 if ( isset( static::$enable_logs_items[ $type ][ $name ] ) ) {
411 return ! empty( static::$enable_logs_items[ $type ][ $name ] ) ? true : false;
412 } else {
413 $un_logs = static::get_data_logs_default( 'unlogs' );
414 if ( ! is_array( $un_logs ) ) {
415 $un_logs = array();
416 }
417 if ( isset( $un_logs[ $name ] ) ) {
418 return empty( $un_logs[ $name ] ) ? false : true; // default is enable log, if disabled in un logs list it will be disabled.
419 }
420 }
421
422 return true;
423 }
424
425 /**
426 * Method get_disabled_logs_type().
427 *
428 * @param string $type Log type dashboard|nonmainwpchanges|changeslogs.
429 *
430 * @return mixed Disabled logs settings.
431 */
432 public static function get_disabled_logs_type( $type = 'dashboard' ) {
433 if ( ! in_array( $type, array( 'dashboard', 'nonmainwpchanges', 'changeslogs' ) ) ) {
434 return false;
435 }
436
437 static::load_actions_logs_selection_settings();
438
439 $selection_items_type = isset( static::$enable_logs_items[ $type ] ) ? static::$enable_logs_items[ $type ] : array();
440
441 if ( ! is_array( $selection_items_type ) || empty( $selection_items_type ) ) {
442 return array();
443 }
444
445 return array_keys(
446 array_filter(
447 $selection_items_type,
448 function ( $value ) {
449 return empty( $value );
450 }
451 )
452 );
453 }
454
455 /**
456 * Method render_logs_data_selection().
457 *
458 * @return void
459 */
460 private static function render_logs_data_selection() { //phpcs:ignore -- NOSONAR - ok.
461 $list_logs = static::get_data_logs_default_to_render();
462 $setting_page = true;
463 ?>
464 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-miscellaneous">
465 <label class="six wide column top aligned">
466 <?php
467 MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-logs-data' );
468 esc_html_e( 'Select events to log', 'mainwp' );
469 ?>
470 </label>
471 <div class="ten wide column" <?php echo $setting_page ? 'data-tooltip="' . esc_attr__( 'Select which types of site changes should be recorded in the logs. Only checked items will generate log entries, helping you focus on the most relevant activity.', 'mainwp' ) . '"' : ''; ?> data-inverted="" data-position="top left">
472 <?php
473 foreach ( $list_logs as $item ) {
474 if ( ! is_array( $item ) ) {
475 continue;
476 }
477 if ( isset( $item['name_id'] ) && '_separator_title' === $item['name_id'] ) {
478 ?>
479 <div class="ui header"><?php echo esc_html( $item['label'] ); ?></div>
480 <?php
481 continue;
482 }
483 ?>
484 <ul class="mainwp_hide_wpmenu_checkboxes">
485 <?php
486
487 $type = isset( $item['log_group'] ) ? $item['log_group'] : '';
488 $name = isset( $item['name_id'] ) ? $item['name_id'] : '';
489 $title = isset( $item['label'] ) ? $item['label'] : '';
490
491 if ( in_array( $type, array( 'dashboard', 'nonmainwpchanges', 'changeslogs' ) ) ) {
492 $_selected = '';
493 if ( static::is_action_log_enabled( $name, $type ) ) {
494 $_selected = 'checked';
495 }
496 ?>
497 <li>
498 <div class="ui checkbox">
499 <input type="checkbox" class="settings-field-value-change-handler" id="mainwp_select_logs_<?php echo esc_attr( $type ); ?>_<?php echo esc_attr( $name ); ?>" name="mainwp_settings_logs_data[<?php echo esc_attr( $type ); ?>][]" <?php echo esc_html( $_selected ); ?> value="<?php echo esc_attr( $name ); ?>">
500 <label for="mainwp_select_logs_<?php echo esc_attr( $type ); ?>_<?php echo esc_attr( $name ); ?>" ><?php echo esc_html( $title ); ?></label>
501 </div>
502 <input type="hidden" name="mainwp_settings_logs_name[<?php echo esc_attr( $type ); ?>][]" value="<?php echo esc_attr( $name ); ?>">
503 </li>
504 <?php
505 }
506 ?>
507 </ul>
508 <?php
509 }
510 ?>
511 </div>
512 </div>
513 <?php
514 }
515
516
517 /**
518 * Method get_data_logs_default().
519 *
520 * @param string $type Type of logs info.
521 *
522 * @return array data.
523 */
524 private static function get_data_logs_default( $type = '' ) {
525
526 $init_un_logs = array(
527 'sites_sync' => 0,
528 );
529
530 $logs = array(
531 'dashboard' => array(
532 'sites_added' => __( 'Site Added', 'mainwp' ),
533 'sites_updated' => __( 'Site Updated', 'mainwp' ),
534 'sites_sync' => __( 'Site Synchronized', 'mainwp' ),
535 'sites_deleted' => __( 'Site Deleted', 'mainwp' ),
536 'sites_reconnect' => __( 'Site Reconnected', 'mainwp' ),
537 'sites_suspend' => __( 'Site Suspended', 'mainwp' ),
538 'sites_unsuspend' => __( 'Site Unsuspended', 'mainwp' ),
539
540 'tags_created' => __( 'Tag Created', 'mainwp' ),
541 'tags_deleted' => __( 'Tag Deleted', 'mainwp' ),
542 'tags_updated' => __( 'Tag Updated', 'mainwp' ),
543
544 'theme_install' => __( 'Theme Installed', 'mainwp' ),
545 'theme_activate' => __( 'Theme Activated', 'mainwp' ),
546 'theme_deactivate' => __( 'Theme Deactivated', 'mainwp' ),
547 'theme_update' => __( 'Theme Updated', 'mainwp' ),
548 'theme_switch' => __( 'Theme Switched', 'mainwp' ),
549 'theme_delete' => __( 'Theme Deleted', 'mainwp' ),
550
551 'plugin_install' => __( 'Plugin Installed', 'mainwp' ),
552 'plugin_activate' => __( 'Plugin Activated', 'mainwp' ),
553 'plugin_deactivate' => __( 'Plugin Deactivated', 'mainwp' ),
554 'plugin_updated' => __( 'Plugin Updated', 'mainwp' ),
555 'plugin_delete' => __( 'Plugin Deleted', 'mainwp' ),
556
557 'translation_updated' => __( 'Translation Updated', 'mainwp' ),
558 'core_updated' => __( 'WordPress Core Updated', 'mainwp' ),
559
560 'post_created' => __( 'Post Created', 'mainwp' ),
561 'post_published' => __( 'Post Published', 'mainwp' ),
562 'post_unpublished' => __( 'Post Unpublished', 'mainwp' ),
563 'post_updated' => __( 'Post Updated', 'mainwp' ),
564 'post_trashed' => __( 'Post Trashed', 'mainwp' ),
565 'post_deleted' => __( 'Post Deleted', 'mainwp' ),
566 'post_restored' => __( 'Post Restored', 'mainwp' ),
567
568 'page_created' => __( 'Page Created', 'mainwp' ),
569 'page_published' => __( 'Page Published', 'mainwp' ),
570 'page_unpublished' => __( 'Page Unpublished', 'mainwp' ),
571 'page_updated' => __( 'Page Updated', 'mainwp' ),
572 'page_trashed' => __( 'Page Trashed', 'mainwp' ),
573 'page_deleted' => __( 'Page Deleted', 'mainwp' ),
574 'page_restored' => __( 'Page Restored', 'mainwp' ),
575
576 'clients_created' => __( 'Client Created', 'mainwp' ),
577 'clients_updated' => __( 'Client Updated', 'mainwp' ),
578 'clients_suspend' => __( 'Client Suspended', 'mainwp' ),
579 'clients_unsuspend' => __( 'Client Unsuspended', 'mainwp' ),
580 'clients_lead' => __( 'Client Marked as Lead', 'mainwp' ),
581 'clients_lost' => __( 'Client Marked as Lost', 'mainwp' ),
582
583 'users_created' => __( 'User Created', 'mainwp' ),
584 'users_update' => __( 'User Updated', 'mainwp' ),
585 'users_delete' => __( 'User Deleted', 'mainwp' ),
586 'users_change_role' => __( 'User Role Changed', 'mainwp' ),
587 'users_update_password' => __( 'Admin Password Updated', 'mainwp' ),
588 ),
589 'nonmainwpchanges' => array(
590 'theme_install' => __( 'Theme Installed', 'mainwp' ),
591 'theme_activate' => __( 'Theme Activated', 'mainwp' ),
592 'theme_deactivate' => __( 'Theme Deactivated', 'mainwp' ),
593 'theme_updated' => __( 'Theme Updated', 'mainwp' ),
594 'theme_switch' => __( 'Theme Switched', 'mainwp' ),
595 'theme_delete' => __( 'Theme Deleted', 'mainwp' ),
596 'plugin_install' => __( 'Plugin Installed', 'mainwp' ),
597 'plugin_activate' => __( 'Plugin Activated', 'mainwp' ),
598 'plugin_deactivate' => __( 'Plugin Deactivated', 'mainwp' ),
599 'plugin_updated' => __( 'Plugin Updated', 'mainwp' ),
600 'plugin_delete' => __( 'Plugin Deleted', 'mainwp' ),
601 'core_updated' => __( 'WordPress Core Updated', 'mainwp' ),
602 ),
603 );
604
605 $logs['changeslogs'] = Log_Changes_Logs_Helper::get_changes_logs_types();
606
607 if ( 'unlogs' === $type ) {
608 return $init_un_logs;
609 }
610
611 return $logs;
612 }
613
614 /**
615 * Method get_data_logs_default_to_render().
616 *
617 * @return array data.
618 */
619 private static function get_data_logs_default_to_render() {
620
621 $list_compatible = array( 1960, 1965, 1970, 1975, 1980 );
622
623 // Convert
624 $list_to_render = array(
625
626 array(
627 'label' => __( 'Events triggered from MainWP Dashboard', 'mainwp' ),
628 'name_id' => '_separator_title',
629 ),
630 array(
631 'label' => __( 'Site Added', 'mainwp' ),
632 'name_id' => 'sites_added',
633 'log_group' => 'dashboard',
634 ),
635 array(
636 'label' => __( 'Site Updated', 'mainwp' ),
637 'name_id' => 'sites_updated',
638 'log_group' => 'dashboard',
639 ),
640 array(
641 'label' => __( 'Site Synchronized', 'mainwp' ),
642 'name_id' => 'sites_sync',
643 'log_group' => 'dashboard',
644 ),
645 array(
646 'label' => __( 'Site Deleted', 'mainwp' ),
647 'name_id' => 'sites_deleted',
648 'log_group' => 'dashboard',
649 ),
650 array(
651 'label' => __( 'Site Reconnected', 'mainwp' ),
652 'name_id' => 'sites_reconnect',
653 'log_group' => 'dashboard',
654 ),
655 array(
656 'label' => __( 'Site Suspended', 'mainwp' ),
657 'name_id' => 'sites_suspend',
658 'log_group' => 'dashboard',
659 ),
660 array(
661 'label' => __( 'Site Unsuspended', 'mainwp' ),
662 'name_id' => 'sites_unsuspend',
663 'log_group' => 'dashboard',
664 ),
665 array(
666 'label' => __( 'Tag Created', 'mainwp' ),
667 'name_id' => 'tags_created',
668 'log_group' => 'dashboard',
669 ),
670 array(
671 'label' => __( 'Tag Deleted', 'mainwp' ),
672 'name_id' => 'tags_deleted',
673 'log_group' => 'dashboard',
674 ),
675 array(
676 'label' => __( 'Tag Updated', 'mainwp' ),
677 'name_id' => 'tags_updated',
678 'log_group' => 'dashboard',
679 ),
680 array(
681 'label' => __( 'Theme Installed', 'mainwp' ),
682 'name_id' => 'theme_install',
683 'log_group' => 'dashboard',
684 ),
685 array(
686 'label' => __( 'Theme Activated', 'mainwp' ),
687 'name_id' => 'theme_activate',
688 'log_group' => 'dashboard',
689 ),
690 array(
691 'label' => __( 'Theme Deactivated', 'mainwp' ),
692 'name_id' => 'theme_deactivate',
693 'log_group' => 'dashboard',
694 ),
695 array(
696 'label' => __( 'Theme Updated', 'mainwp' ),
697 'name_id' => 'theme_update',
698 'log_group' => 'dashboard',
699 ),
700 array(
701 'label' => __( 'Theme Switched', 'mainwp' ),
702 'name_id' => 'theme_switch',
703 'log_group' => 'dashboard',
704 ),
705 array(
706 'label' => __( 'Theme Deleted', 'mainwp' ),
707 'name_id' => 'theme_delete',
708 'log_group' => 'dashboard',
709 ),
710 array(
711 'label' => __( 'Plugin Installed', 'mainwp' ),
712 'name_id' => 'plugin_install',
713 'log_group' => 'dashboard',
714 ),
715 array(
716 'label' => __( 'Plugin Activated', 'mainwp' ),
717 'name_id' => 'plugin_activate',
718 'log_group' => 'dashboard',
719 ),
720 array(
721 'label' => __( 'Plugin Deactivated', 'mainwp' ),
722 'name_id' => 'plugin_deactivate',
723 'log_group' => 'dashboard',
724 ),
725 array(
726 'label' => __( 'Plugin Updated', 'mainwp' ),
727 'name_id' => 'plugin_updated',
728 'log_group' => 'dashboard',
729 ),
730 array(
731 'label' => __( 'Plugin Deleted', 'mainwp' ),
732 'name_id' => 'plugin_delete',
733 'log_group' => 'dashboard',
734 ),
735 array(
736 'label' => __( 'Translation Updated', 'mainwp' ),
737 'name_id' => 'translation_updated',
738 'log_group' => 'dashboard',
739 ),
740 array(
741 'label' => __( 'WordPress Core Updated', 'mainwp' ),
742 'name_id' => 'core_updated',
743 'log_group' => 'dashboard',
744 ),
745 array(
746 'label' => __( 'Post Created', 'mainwp' ),
747 'name_id' => 'post_created',
748 'log_group' => 'dashboard',
749 ),
750 array(
751 'label' => __( 'Post Published', 'mainwp' ),
752 'name_id' => 'post_published',
753 'log_group' => 'dashboard',
754 ),
755 array(
756 'label' => __( 'Post Unpublished', 'mainwp' ),
757 'name_id' => 'post_unpublished',
758 'log_group' => 'dashboard',
759 ),
760 array(
761 'label' => __( 'Post Updated', 'mainwp' ),
762 'name_id' => 'post_updated',
763 'log_group' => 'dashboard',
764 ),
765 array(
766 'label' => __( 'Post Trashed', 'mainwp' ),
767 'name_id' => 'post_trashed',
768 'log_group' => 'dashboard',
769 ),
770 array(
771 'label' => __( 'Post Deleted', 'mainwp' ),
772 'name_id' => 'post_deleted',
773 'log_group' => 'dashboard',
774 ),
775 array(
776 'label' => __( 'Post Restored', 'mainwp' ),
777 'name_id' => 'post_restored',
778 'log_group' => 'dashboard',
779 ),
780 array(
781 'label' => __( 'Page Created', 'mainwp' ),
782 'name_id' => 'page_created',
783 'log_group' => 'dashboard',
784 ),
785 array(
786 'label' => __( 'Page Published', 'mainwp' ),
787 'name_id' => 'page_published',
788 'log_group' => 'dashboard',
789 ),
790 array(
791 'label' => __( 'Page Unpublished', 'mainwp' ),
792 'name_id' => 'page_unpublished',
793 'log_group' => 'dashboard',
794 ),
795 array(
796 'label' => __( 'Page Updated', 'mainwp' ),
797 'name_id' => 'page_updated',
798 'log_group' => 'dashboard',
799 ),
800 array(
801 'label' => __( 'Page Trashed', 'mainwp' ),
802 'name_id' => 'page_trashed',
803 'log_group' => 'dashboard',
804 ),
805 array(
806 'label' => __( 'Page Deleted', 'mainwp' ),
807 'name_id' => 'page_deleted',
808 'log_group' => 'dashboard',
809 ),
810 array(
811 'label' => __( 'Page Restored', 'mainwp' ),
812 'name_id' => 'page_restored',
813 'log_group' => 'dashboard',
814 ),
815 array(
816 'label' => __( 'Client Created', 'mainwp' ),
817 'name_id' => 'clients_created',
818 'log_group' => 'dashboard',
819 ),
820 array(
821 'label' => __( 'Client Updated', 'mainwp' ),
822 'name_id' => 'clients_updated',
823 'log_group' => 'dashboard',
824 ),
825 array(
826 'label' => __( 'Client Suspended', 'mainwp' ),
827 'name_id' => 'clients_suspend',
828 'log_group' => 'dashboard',
829 ),
830 array(
831 'label' => __( 'Client Unsuspended', 'mainwp' ),
832 'name_id' => 'clients_unsuspend',
833 'log_group' => 'dashboard',
834 ),
835 array(
836 'label' => __( 'Client Marked as Lead', 'mainwp' ),
837 'name_id' => 'clients_lead',
838 'log_group' => 'dashboard',
839 ),
840 array(
841 'label' => __( 'Client Marked as Lost', 'mainwp' ),
842 'name_id' => 'clients_lost',
843 'log_group' => 'dashboard',
844 ),
845 array(
846 'label' => __( 'User Created', 'mainwp' ),
847 'name_id' => 'users_created',
848 'log_group' => 'dashboard',
849 ),
850 array(
851 'label' => __( 'User Updated', 'mainwp' ),
852 'name_id' => 'users_update',
853 'log_group' => 'dashboard',
854 ),
855 array(
856 'label' => __( 'User Deleted', 'mainwp' ),
857 'name_id' => 'users_delete',
858 'log_group' => 'dashboard',
859 ),
860 array(
861 'label' => __( 'User Role Changed', 'mainwp' ),
862 'name_id' => 'users_change_role',
863 'log_group' => 'dashboard',
864 ),
865 array(
866 'label' => __( 'Admin Password Updated', 'mainwp' ),
867 'name_id' => 'users_update_password',
868 'log_group' => 'dashboard',
869 ),
870 array(
871 'label' => __( 'Non-MainWP Changes - Events triggered on child sites', 'mainwp' ),
872 'name_id' => '_separator_title',
873 ),
874 array(
875 'label' => __( 'Theme Installed', 'mainwp' ),
876 'name_id' => 1975,
877 'log_group' => 'changeslogs',
878 ),
879 array(
880 'label' => __( 'Theme Activated', 'mainwp' ),
881 'name_id' => 'theme_activate',
882 'log_group' => 'nonmainwpchanges',
883 ),
884 array(
885 'label' => __( 'Theme Deactivated', 'mainwp' ),
886 'name_id' => 'theme_deactivate',
887 'log_group' => 'nonmainwpchanges',
888 ),
889 array(
890 'label' => __( 'Theme Updated', 'mainwp' ),
891 'name_id' => 1980,
892 'log_group' => 'changeslogs',
893 ),
894 array(
895 'label' => __( 'Theme Switched', 'mainwp' ),
896 'name_id' => 'theme_switch',
897 'log_group' => 'nonmainwpchanges',
898 ),
899 array(
900 'label' => __( 'Theme Deleted', 'mainwp' ),
901 'name_id' => 'theme_delete',
902 'log_group' => 'nonmainwpchanges',
903 ),
904 array(
905 'label' => __( 'Plugin Installed', 'mainwp' ),
906 'name_id' => 1965,
907 'log_group' => 'changeslogs',
908 ),
909 array(
910 'label' => __( 'Plugin Activated', 'mainwp' ),
911 'name_id' => 'plugin_activate',
912 'log_group' => 'nonmainwpchanges',
913 ),
914 array(
915 'label' => __( 'Plugin Deactivated', 'mainwp' ),
916 'name_id' => 'plugin_deactivate',
917 'log_group' => 'nonmainwpchanges',
918 ),
919 array(
920 'label' => __( 'Plugin Updated', 'mainwp' ),
921 'name_id' => 1970,
922 'log_group' => 'changeslogs',
923 ),
924 array(
925 'label' => __( 'Plugin Deleted', 'mainwp' ),
926 'name_id' => 'plugin_delete',
927 'log_group' => 'nonmainwpchanges',
928 ),
929 array(
930 'label' => __( 'WordPress Core Updated', 'mainwp' ),
931 'name_id' => 1960,
932 'log_group' => 'changeslogs',
933 ),
934 );
935
936 $raw_logs = Log_Changes_Logs_Helper::get_changes_logs_types();
937
938 foreach ( $raw_logs as $item ) {
939
940 if ( ! empty( $item['type_id'] ) && in_array( $item['type_id'], $list_compatible ) ) {
941 continue;
942 }
943
944 $list_to_render[] = array(
945 'label' => $item['desc'],
946 'name_id' => $item['type_id'],
947 'log_group' => 'changeslogs',
948 );
949 }
950
951 return $list_to_render;
952 }
953 }
954