PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.2.2
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 / pages / page-mainwp-overview.php

page-mainwp-overview.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.2.2, at pages/page-mainwp-overview.php

452 lines 17.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Overview Page.
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 /**
11 * Class MainWP_Overview
12 *
13 * @package MainWP\Dashboard
14 */
15 class MainWP_Overview { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
16
17 /**
18 * Get Class Name
19 *
20 * @return string __CLASS__
21 */
22 public static function get_class_name() {
23 return __CLASS__;
24 }
25
26 /**
27 * The single instance of the class
28 *
29 * @var mixed Default null
30 */
31 protected static $instance = null;
32
33 /**
34 * Screen dashdoard ID value.
35 *
36 * @var int $dashBoard default 0.
37 */
38 public $dashBoard = 0;
39
40 /**
41 * Enabled widgets
42 *
43 * @var array $enable_widgets
44 */
45 private static $enable_widgets = array(
46 'overview' => true,
47 'connection_status' => true,
48 'recent_posts' => true,
49 'recent_pages' => true,
50 'security_issues' => true,
51 'backup_tasks' => true,
52 'non_mainwp_changes' => true,
53 'clients' => true,
54 'get-started' => true,
55 );
56
57 /**
58 * Check if there is a session,
59 * if there isn't one create it.
60 *
61 * @return static::singlton Overview Page Session.
62 *
63 * @uses \MainWP\Dashboard\MainWP_Overview
64 */
65 public static function get() {
66 if ( null === static::$instance ) {
67 static::$instance = new MainWP_Overview();
68 }
69
70 return static::$instance;
71 }
72
73 /**
74 * MainWP_Overview constructor.
75 *
76 * Run each time the class is called.
77 */
78 public function __construct() {
79 add_filter( 'screen_layout_columns', array( &$this, 'on_screen_layout_columns' ), 10, 2 );
80 add_action( 'admin_menu', array( &$this, 'on_admin_menu' ) );
81 add_action( 'mainwp_help_sidebar_content', array( &$this, 'mainwp_help_content' ) );
82 }
83
84 /**
85 * Set the number of page coumns.
86 *
87 * @param mixed $columns Number of Columns.
88 * @param mixed $screen Screen size.
89 *
90 * @return int $columns Number of desired page columns.
91 */
92 public function on_screen_layout_columns( $columns, $screen ) {
93 if ( $screen === $this->dashBoard ) {
94 $columns[ $this->dashBoard ] = 3;
95 }
96
97 return $columns;
98 }
99
100 /**
101 * Add MainWP Overview top level menu.
102 *
103 * @uses \MainWP\Dashboard\MainWP_System_Utility::is_admin()
104 * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit()
105 */
106 public function on_admin_menu() {
107 if ( MainWP_System_Utility::is_admin() ) {
108
109 /**
110 * Current user global.
111 *
112 * @global string
113 */
114 global $current_user;
115
116 // The icon in Base64 format.
117 $icon_base64 = 'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAyNi4zLjEsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiDQoJIHZpZXdCb3g9IjAgMCA1MCA1MCIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgNTAgNTA7IiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxzdHlsZSB0eXBlPSJ0ZXh0L2NzcyI+DQoJLnN0MHtmaWxsOiM5Q0EyQTc7fQ0KPC9zdHlsZT4NCjxwYXRoIGNsYXNzPSJzdDAiIGQ9Ik0yNSwwLjVDMTEuNDcsMC41LDAuNSwxMS40NywwLjUsMjVjMCwxMy41MywxMC45NywyNC41LDI0LjUsMjQuNVM0OS41LDM4LjUzLDQ5LjUsMjUNCglDNDkuNSwxMS40NywzOC41MywwLjUsMjUsMC41eiBNMjUsNDQuNmwtOC4zMy00LjlsNi4wOS0yNS4wN2MtMS41Ny0wLjgyLTIuNjYtMi40NC0yLjY2LTQuMzNjMC0yLjcxLDIuMTktNC45LDQuOS00LjkNCglzNC45LDIuMTksNC45LDQuOWMwLDEuODktMS4wOSwzLjUyLTIuNjYsNC4zM2w2LjA5LDI1LjA3TDI1LDQ0LjZ6Ii8+DQo8L3N2Zz4NCg==';
118
119 // The icon in the data URI scheme.
120 $icon_data_uri = 'data:image/svg+xml;base64,' . $icon_base64;
121
122 delete_user_option( $current_user->ID, 'screen_layout_toplevel_page_mainwp_tab' );
123
124 $this->dashBoard = add_menu_page(
125 'MainWP',
126 'MainWP',
127 'read',
128 'mainwp_tab',
129 array(
130 $this,
131 'on_show_page',
132 ),
133 $icon_data_uri,
134 '2.00001'
135 );
136
137 add_submenu_page(
138 'mainwp_tab',
139 'MainWP',
140 __( 'Overview', 'mainwp' ),
141 'read',
142 'mainwp_tab',
143 array(
144 $this,
145 'on_show_page',
146 )
147 );
148
149 $val = get_user_option( 'screen_layout_' . $this->dashBoard );
150 if ( ! MainWP_Utility::ctype_digit( $val ) ) {
151 update_user_option( $current_user->ID, 'screen_layout_' . $this->dashBoard, 2, true );
152 }
153 add_action( 'load-' . $this->dashBoard, array( &$this, 'on_load_page' ) );
154 static::init_left_menu();
155
156 }
157 }
158
159 /**
160 * Instantiate the MainWP Overview Menu item.
161 *
162 * @uses \MainWP\Dashboard\MainWP_Menu::add_left_menu()
163 */
164 public static function init_left_menu() {
165 MainWP_Menu::add_left_menu(
166 array(
167 'title' => esc_html__( 'Overview', 'mainwp' ),
168 'parent_key' => 'mainwp_tab',
169 'slug' => 'mainwp_tab',
170 'href' => 'admin.php?page=mainwp_tab',
171 'icon' => '<i class="th large icon"></i>',
172 ),
173 0
174 );
175 }
176
177 /**
178 * Method on_load_page()
179 *
180 * Run on page load.
181 */
182 public function on_load_page() {
183 wp_enqueue_script( 'common' );
184 wp_enqueue_script( 'wp-lists' );
185 wp_enqueue_script( 'postbox' );
186 wp_enqueue_script( 'dashboard' );
187 wp_enqueue_script( 'widgets' );
188
189 static::add_meta_boxes( $this->dashBoard );
190 }
191
192 /**
193 * Method add_meta_boxes()
194 *
195 * Add MainWP Overview Page Widgets.
196 *
197 * @param array $page Current page.
198 *
199 * @uses \MainWP\Dashboard\MainWP_System_Handler::apply_filters()
200 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_current_wpid()
201 * @uses \MainWP\Dashboard\MainWP_UI::add_widget_box()
202 * @uses \MainWP\Dashboard\MainWP_Connection_Status::get_class_name()
203 * @uses \MainWP\Dashboard\MainWP_Recent_Pages::get_class_name()
204 * @uses \MainWP\Dashboard\MainWP_Recent_Posts::get_class_name()
205 * @uses \MainWP\Dashboard\MainWP_Security_Issues_Widget::get_class_name()
206 * @uses \MainWP\Dashboard\MainWP_Updates_Overview::get_class_name()
207 */
208 public static function add_meta_boxes( $page ) { // phpcs:ignore -- NOSONAR - complex method. Current complexity is the only way to achieve desired results, pull request solutions appreciated.
209
210 /**
211 * Get getmetaboxes
212 *
213 * Adds metaboxes (widgets) to the Overview page.
214 *
215 * @since Unknown
216 */
217 $extMetaBoxs = MainWP_System_Handler::instance()->apply_filters( 'mainwp-getmetaboxes', array() );
218 $extMetaBoxs = MainWP_System_Handler::instance()->apply_filters( 'mainwp_getmetaboxes', $extMetaBoxs ); // hooks to load widgets for general overview dashboard page.
219
220 foreach ( $extMetaBoxs as $box ) {
221 if ( isset( $box['plugin'] ) ) {
222 $name = basename( $box['plugin'], '.php' );
223 static::$enable_widgets[ $name ] = true;
224 }
225 }
226
227 $values = static::$enable_widgets;
228
229 /**
230 * Unset unwanted Widgets
231 *
232 * Contains the list of enabled widgets and allows user to unset unwanted widgets.
233 *
234 * @param array $values Array containing enabled widgets.
235 * @param int $dashboard_siteid Child site (Overview) ID.
236 *
237 * @since 4.0
238 */
239 $values = apply_filters( 'mainwp_overview_enabled_widgets', $values, null );
240 static::$enable_widgets = array_merge( static::$enable_widgets, $values );
241
242 $i = 1;
243 foreach ( $extMetaBoxs as $metaBox ) {
244 $enabled = true;
245 if ( isset( $metaBox['plugin'] ) ) {
246 $name = basename( $metaBox['plugin'], '.php' );
247 if ( isset( static::$enable_widgets[ $name ] ) && ! static::$enable_widgets[ $name ] ) {
248 $enabled = false;
249 }
250 }
251
252 $id = isset( $metaBox['id'] ) ? $metaBox['id'] : $i++;
253 $id = 'advanced-' . $id;
254
255 if ( $enabled ) {
256 if ( 'google-widget' === $id || 'matomo' === $id ) {
257 MainWP_UI::add_widget_box( $id, $metaBox['callback'], $page, array( 1, 1, 4, 18 ) );
258 } else {
259 MainWP_UI::add_widget_box( $id, $metaBox['callback'], $page, array( 1, 1, 4, 11 ) );
260 }
261 }
262 }
263
264 // Load the Updates Overview widget.
265 if ( static::$enable_widgets['get-started'] ) {
266 MainWP_UI::add_widget_box( 'get-started', array( MainWP_Get_Started::get_class_name(), 'render' ), $page, array( 1, 1, 4, 11 ) );
267 }
268
269 // Load the Recent Posts widget.
270 if ( mainwp_current_user_have_right( 'dashboard', 'manage_posts' ) && static::$enable_widgets['recent_posts'] ) {
271 MainWP_UI::add_widget_box( 'recent_posts', array( MainWP_Recent_Posts::get_class_name(), 'render' ), $page, array( 1, 1, 6, 11 ) );
272 }
273
274 // Load the Recent Pages widget.
275 if ( mainwp_current_user_have_right( 'dashboard', 'manage_pages' ) && static::$enable_widgets['recent_pages'] ) {
276 MainWP_UI::add_widget_box( 'recent_pages', array( MainWP_Recent_Pages::get_class_name(), 'render' ), $page, array( 1, 1, 6, 11 ) );
277 }
278
279 // Load the Security Issues widget.
280 if ( mainwp_current_user_have_right( 'dashboard', 'manage_security_issues' ) && static::$enable_widgets['security_issues'] ) {
281 MainWP_UI::add_widget_box( 'security_issues', array( MainWP_Security_Issues_Widget::get_class_name(), 'render_widget' ), $page, array( 1, 1, 4, 4 ) );
282 }
283
284 // Load the Connection Status widget.
285 if ( ! MainWP_System_Utility::get_current_wpid() && static::$enable_widgets['connection_status'] ) {
286 MainWP_UI::add_widget_box( 'connection_status', array( MainWP_Connection_Status::get_class_name(), 'render' ), $page, array( 1, 1, 4, 5 ) );
287 }
288
289 // Load the Non-MainWP Changes widget.
290 if ( static::$enable_widgets['non_mainwp_changes'] ) {
291 MainWP_UI::add_widget_box( 'non_mainwp_changes', array( MainWP_Site_Actions::get_class_name(), 'render' ), $page, array( 1, 1, 4, 18 ) );
292 }
293
294 // Load the Clients widget.
295 if ( static::$enable_widgets['clients'] ) {
296 MainWP_UI::add_widget_box( 'clients', array( MainWP_Clients::get_class_name(), 'render' ), $page, array( 1, 1, 4, 9 ) );
297 }
298
299 // Load the Updates Overview widget.
300 if ( static::$enable_widgets['overview'] ) {
301 MainWP_UI::add_widget_box( 'overview', array( MainWP_Updates_Overview::get_class_name(), 'render' ), $page, array( 1, 1, 4, 18 ) );
302 }
303 }
304
305 /**
306 * Method on_show_page()
307 *
308 * When the page loads render the body content.
309 *
310 * @uses \MainWP\Dashboard\MainWP_UI::render_top_header()
311 * @uses \MainWP\Dashboard\MainWP_UI::render_second_top_header()
312 */
313 public function on_show_page() {
314 if ( ! mainwp_current_user_have_right( 'dashboard', 'access_global_dashboard' ) ) {
315 mainwp_do_not_have_permissions( esc_html__( 'global dashboard', 'mainwp' ) );
316 return;
317 }
318
319 /**
320 * Screen layout columns array.
321 *
322 * @global object
323 */
324 global $screen_layout_columns;
325
326 $params = array(
327 'title' => esc_html__( 'Overview', 'mainwp' ),
328 );
329
330 MainWP_UI::render_top_header( $params );
331
332 MainWP_UI::render_second_top_header();
333
334 static::render_dashboard_body();
335 ?>
336 </div>
337 <?php
338 }
339
340
341 /**
342 * Method render_dashboard_body()
343 *
344 * Render the Dashboard Body content.
345 *
346 * @param object $websites Object containing child sites info.
347 *
348 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_current_wpid()
349 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_page_id()
350 * @uses \MainWP\Dashboard\MainWP_UI::do_widget_boxes()
351 * @uses \MainWP\Dashboard\MainWP_Utility::show_mainwp_message()
352 */
353 public static function render_dashboard_body( $websites = array() ) {
354 $current_wp_id = MainWP_System_Utility::get_current_wpid();
355 $website = null;
356 if ( ! empty( $current_wp_id ) ) {
357 $website = $websites[0];
358 }
359 $screen = get_current_screen();
360
361 MainWP_Demo_Handle::get_instance()->init_data_demo();
362 ?>
363 <div class="mainwp-primary-content-wrap">
364 <div class="ui segment" style="padding-top:0px;padding-bottom:0px;margin-bottom:0px;">
365 <div id="mainwp-dashboard-info-box"></div>
366 <?php
367 if ( ! empty( $current_wp_id ) && ! empty( $website->sync_errors ) ) {
368 ?>
369 <div class="ui red message">
370 <p><?php echo '<strong>' . esc_html( stripslashes( $website->name ) ) . '</strong>' . esc_html__( ' is Disconnected. Click the Reconnect button to establish the connection again.', 'mainwp' ); ?></p>
371 </div>
372 <?php
373 }
374 ?>
375 <div id="mainwp-message-zone" class="ui message" style="display:none;"></div>
376 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'widgets' ) ) : ?>
377 <div class="ui info message">
378 <i class="close icon mainwp-notice-dismiss" notice-id="widgets"></i>
379 <?php printf( esc_html__( 'To hide or show a widget, click the Cog (%1$s) icon.', 'mainwp' ), '<i class="cog icon"></i>' ); ?>
380 </div>
381 <?php endif; ?>
382 </div>
383 <?php
384 /**
385 * Action: mainwp_before_overview_widgets
386 *
387 * Fires at the top of the Overview page (before first widget).
388 *
389 * @since 4.1
390 */
391 do_action( 'mainwp_before_overview_widgets', 'dashboard' );
392 ?>
393 <div id="mainwp-grid-wrapper" class="gridster">
394 <?php MainWP_UI::do_widget_boxes( $screen->id ); ?>
395 </div>
396 <?php
397 /**
398 * Action: 'mainwp_after_overview_widgets'
399 *
400 * Fires at the bottom of the Overview page (after the last widget).
401 *
402 * @since 4.1
403 */
404 do_action( 'mainwp_after_overview_widgets', 'dashboard' );
405 ?>
406 <script type="text/javascript">
407 jQuery( document ).ready( function( $ ) {
408 jQuery( '.mainwp-widget .mainwp-dropdown-tab .item' ).tab();
409 mainwp_get_icon_start();
410 } );
411 </script>
412 <?php
413 MainWP_UI::render_modal_upload_icon();
414 MainWP_Updates::render_plugin_details_modal();
415 }
416
417 /**
418 * Method mainwp_help_content()
419 *
420 * Creates the MainWP Help Documentation List for the help component in the sidebar.
421 */
422 public static function mainwp_help_content() {
423 if ( isset( $_GET['page'] ) && 'mainwp_tab' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
424 ?>
425 <p><?php esc_html_e( 'If you need help with your MainWP Dashboard, please review following help documents', 'mainwp' ); ?></p>
426 <div class="ui list">
427 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/mainwp-user-interface/" target="_blank">Understanding MainWP Dashboard UI</a></div>
428 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/mainwp-user-interface/#navigation" target="_blank">MainWP Navigation</a></div>
429 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/mainwp-user-interface/#page-settings" target="_blank">Page Settings</a></div>
430 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/mainwp-user-interface/#widgetized-page-layout" target="_blank">Widgetized Page Layout</a></div>
431 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/mainwp-user-interface/#tables" target="_blank">MainWP Tables</a></div>
432 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/mainwp-user-interface/#individual-site-mode" target="_blank">Individual Child Site Mode</a></div>
433 <?php
434 /**
435 * Action: mainwp_overview_help_item
436 *
437 * Fires at the bottom of the help articles list in the Help sidebar on the Overview page.
438 *
439 * Suggested HTML markup:
440 *
441 * <div class="item"><a href="Your custom URL">Your custom text</a></div>
442 *
443 * @since 4.1
444 */
445 do_action( 'mainwp_overview_help_item' );
446 ?>
447 </div>
448 <?php
449 }
450 }
451 }
452