PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.1
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 / widgets / widget-log-users-widget.php

widget-log-users-widget.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 6.1, at modules/logs/widgets/widget-log-users-widget.php

215 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Logs Widget
4 *
5 * Displays the Logs Info.
6 *
7 * @package MainWP/Dashboard
8 * @version 4.6
9 */
10
11 namespace MainWP\Dashboard\Module\Log;
12
13 use MainWP\Dashboard\MainWP_Utility;
14 use MainWP\Dashboard\MainWP_UI;
15
16 // Exit if accessed directly.
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit;
19 }
20
21
22 /**
23 * Class Log_Users_Widget
24 *
25 * Displays the Logs info.
26 */
27 class Log_Users_Widget {
28
29 /**
30 * Protected static variable to hold the single instance of the class.
31 *
32 * @var mixed Default null
33 */
34 protected static $instance = null;
35
36 /**
37 * Return the single instance of the class.
38 *
39 * @return mixed $instance The single instance of the class.
40 */
41 public static function instance() {
42 if ( is_null( static::$instance ) ) {
43 static::$instance = new self();
44 }
45 return static::$instance;
46 }
47
48
49 /**
50 * Method get_class_name()
51 *
52 * @return string __CLASS__ Class name.
53 */
54 public static function get_class_name() {
55 return __CLASS__;
56 }
57
58 /**
59 * Method render()
60 *
61 * @param array ...$args Widget callback args.
62 * @return mixed render_site_info()
63 */
64 public function render( ...$args ) {
65 $this->render_widget( $args );
66 }
67
68
69 /**
70 * Render client overview Info.
71 *
72 * @param array $args Args data.
73 */
74 public function render_widget( $args ) {
75 $data = is_array( $args ) && ! empty( $args[1][0] ) && is_array( $args[1][0] ) ? $args[1][0] : array();
76 $stats_data = is_array( $data ) && ! empty( $data['stats_data']['users']['users'] ) ? $data['stats_data']['users']['users'] : array();
77 if ( ! is_array( $stats_data ) ) {
78 $stats_data = array();
79 }
80
81 $stats_prev_data = is_array( $data ) && ! empty( $data['stats_prev_data']['users']['users'] ) ? $data['stats_prev_data']['users']['users'] : array();
82 if ( ! is_array( $stats_prev_data ) ) {
83 $stats_prev_data = array();
84 }
85
86 ?>
87 <div class="mainwp-widget-header">
88 <h2 class="ui header handle-drag">
89 <?php esc_html_e( 'User Management Events Summary', 'mainwp' ); ?>
90 <div class="sub header">
91 <?php esc_html_e( 'Displays a tally of user-related actions with a total event count.', 'mainwp' ); ?>
92 </div>
93 </h2>
94 </div>
95
96 <div class="mainwp-widget-insights-card mainwp-scrolly-overflow">
97 <?php
98 /**
99 * Action: mainwp_logs_widget_top
100 *
101 * Fires at the top of the widget.
102 *
103 * @since 4.6
104 */
105 do_action( 'mainwp_logs_widget_top', 'users' );
106 ?>
107 <div id="mainwp-message-zone" style="display:none;" class="ui message"></div>
108 <?php
109 MainWP_UI::generate_wp_nonce( 'mainwp-admin-nonce' );
110 if ( ! empty( $data ) ) {
111 $this->render_widget_content( $stats_data, $stats_prev_data );
112 } else {
113 MainWP_UI::render_empty_element_placeholder( __( 'No activity recorded', 'mainwp' ), __( 'Data will appear here once actions are tracked.', 'mainwp' ), '<em data-emoji=":bar_chart:" class="medium"></em>' );
114 }
115 ?>
116 <?php
117 /**
118 * Action: mainwp_logs_widget_bottom
119 *
120 * Fires at the bottom of the widget.
121 *
122 * @since 4.6
123 */
124 do_action( 'mainwp_logs_widget_bottom', 'users' );
125 ?>
126 </div>
127 <div class="mainwp-widget-footer ui four columns stackable grid">
128 <div class="column">
129 </div>
130 <div class="column">
131 </div>
132 </div>
133 <?php
134 }
135
136 /**
137 * Method render_widget_content().
138 *
139 * @param array $data Stats data.
140 * @param array $prev_data Previous stats data.
141 */
142 public function render_widget_content( $data, $prev_data ) {
143 $columns = array(
144 'created' => esc_html__( 'Created', 'mainwp' ),
145 'updated' => esc_html__( 'Updated', 'mainwp' ),
146 'delete' => esc_html__( 'Deleted', 'mainwp' ),
147 'update_password' => esc_html__( 'Password Updates', 'mainwp' ),
148 'change_role' => esc_html__( 'Role Changes', 'mainwp' ),
149 'total_events' => esc_html__( 'Total', 'mainwp' ),
150 );
151 ?>
152 <div class="ui grid">
153 <div class="sixteen wide column">
154 <div class="ui equal width grid">
155 <?php
156 foreach ( $columns as $act => $title ) {
157 Log_Stats::render_stats_info( $data, $act, $title, $prev_data );
158 }
159 ?>
160 </div>
161 </div>
162 <div class="sixteen wide column">
163 <div id="mainwp-module-log-chart-users-management-wrapper" ></div>
164 <script type="text/javascript">
165 jQuery( document ).ready( function() {
166 let options = {
167 chart: {
168 type: 'bar',
169 height: 350,
170 },
171 plotOptions: {
172 bar: {
173 columnWidth: '60%'
174 }
175 },
176 series: [ {
177 name: 'Events:',
178 data: [
179 <?php
180 foreach ( $columns as $act => $title ) {
181 Log_Stats::render_chart_series( $data, $act, $title, $prev_data );
182 }
183 ?>
184 ],
185 } ],
186 xaxis: {
187 labels: {
188 style: {
189 colors: '#999999',
190 }
191 }
192 },
193 yaxis: {
194 labels: {
195 style: {
196 colors: '#999999',
197 }
198 }
199 },
200 tooltip: {
201 theme: 'dark'
202 },
203 }
204 let clients = new ApexCharts(document.querySelector("#mainwp-module-log-chart-users-management-wrapper"), options);
205 setTimeout(() => {
206 clients.render();
207 }, 1000);
208 } );
209 </script>
210 </div>
211 </div>
212 <?php
213 }
214 }
215