PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.1
6.2.2 6.2.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 All 155 releases
mainwp / pages / page-mainwp-client-overview.php

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

556 lines 23.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Client Overview Page.
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 // Exit if accessed directly.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Class MainWP_Overview
17 *
18 * @package MainWP\Dashboard
19 */
20 class MainWP_Client_Overview { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
21
22 /**
23 * Get Class Name
24 *
25 * @return string __CLASS__
26 */
27 public static function get_class_name() {
28 return __CLASS__;
29 }
30
31 /**
32 * The single instance of the class
33 *
34 * @var mixed Default null
35 */
36 protected static $instance = null;
37
38 /**
39 * Enabled widgets
40 *
41 * @var array $enable_widgets
42 */
43 private static $enable_widgets = array(
44 'overview' => true,
45 'note' => true,
46 'fields_info' => true,
47 'websites' => true,
48 'recent_posts' => true,
49 'recent_pages' => true,
50 'non_mainwp_changes' => true,
51 );
52
53 /**
54 * Current page.
55 *
56 * @static
57 * @var string $page Current page.
58 */
59 public static $page;
60
61 /**
62 * Check if there is a session,
63 * if there isn't one create it.
64 *
65 * @return static::singlton Overview Page Session.
66 *
67 * @uses \MainWP\Dashboard\MainWP_Overview
68 */
69 public static function instance() {
70 if ( null === static::$instance ) {
71 static::$instance = new self();
72 }
73
74 return static::$instance;
75 }
76
77 /**
78 * MainWP_Overview constructor.
79 *
80 * Run each time the class is called.
81 */
82 public function __construct() {
83 add_filter( 'screen_layout_columns', array( &$this, 'on_screen_layout_columns' ), 10, 2 );
84 add_action( 'mainwp_help_sidebar_content', array( &$this, 'mainwp_help_content' ) );
85 }
86
87 /**
88 * Set the number of page coumns.
89 *
90 * @param mixed $columns Number of Columns.
91 * @param mixed $screen Screen size.
92 *
93 * @return int $columns Number of desired page columns.
94 */
95 public function on_screen_layout_columns( $columns, $screen ) {
96 if ( $screen === static::$page ) {
97 $columns[ static::$page ] = 3;
98 }
99
100 return $columns;
101 }
102
103
104 /**
105 * Method on_load_page()
106 *
107 * Run on page load.
108 *
109 * @param mixed $page Page name.
110 */
111 public static function on_load_page( $page ) {
112
113 static::$page = $page;
114
115 $val = get_user_option( 'screen_layout_' . $page );
116 if ( ! $val ) {
117 global $current_user;
118 update_user_option( $current_user->ID, 'screen_layout_' . $page, 2, true );
119 }
120
121 wp_enqueue_script( 'common' );
122 wp_enqueue_script( 'wp-lists' );
123 wp_enqueue_script( 'postbox' );
124 wp_enqueue_script( 'dashboard' );
125 wp_enqueue_script( 'widgets' );
126
127 static::add_meta_boxes( $page );
128
129 add_filter( 'mainwp_header_actions_right', array( static::get_class_name(), 'screen_options' ), 10, 2 );
130 }
131
132 /**
133 * Method screen_options()
134 *
135 * Create Page Settings button.
136 *
137 * @param mixed $input Page Settings button HTML.
138 *
139 * @return mixed Page Settings button.
140 */
141 public static function screen_options( $input ) {
142 return $input .
143 '<a class="ui button basic icon" onclick="mainwp_clients_overview_screen_options(); return false;" data-inverted="" data-position="bottom right" href="#" target="_blank" data-tooltip="' . esc_html__( 'Page Settings', 'mainwp' ) . '">
144 <i class="cog icon"></i>
145 </a>';
146 }
147
148 /**
149 * Method add_meta_boxes()
150 *
151 * Add MainWP Overview Page Widgets.
152 *
153 * @param array $page Current page.
154 *
155 * @uses \MainWP\Dashboard\MainWP_System_Handler::apply_filters()
156 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_current_wpid()
157 * @uses \MainWP\Dashboard\MainWP_UI::add_widget_box()
158 * @uses \MainWP\Dashboard\MainWP_Connection_Status::get_class_name()
159 * @uses \MainWP\Dashboard\MainWP_Recent_Pages::get_class_name()
160 * @uses \MainWP\Dashboard\MainWP_Recent_Posts::get_class_name()
161 * @uses \MainWP\Dashboard\MainWP_Security_Issues_Widget::get_class_name()
162 * @uses \MainWP\Dashboard\MainWP_Updates_Overview::get_class_name()
163 */
164 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.
165
166 /**
167 * Get getmetaboxes
168 *
169 * Adds metaboxes (widgets) to the Operations page.
170 *
171 * @since 4.3
172 */
173 $extMetaBoxs = array();
174 $extMetaBoxs = apply_filters( 'mainwp_clients_getmetaboxes', $extMetaBoxs );
175 foreach ( $extMetaBoxs as $box ) {
176 if ( isset( $box['plugin'] ) ) {
177 $name = basename( $box['plugin'], '.php' );
178 static::$enable_widgets[ $name ] = true;
179 } elseif ( ! empty( $box['widget_id'] ) ) {
180 static::$enable_widgets[ $box['widget_id'] ] = true;
181 }
182 }
183
184 $client_contacts = array();
185 if ( isset( $_GET['client_id'] ) && ! empty( $_GET['client_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
186 $client_contacts = MainWP_DB_Client::instance()->get_wp_client_contact_by( 'client_id', intval( $_GET['client_id'] ), ARRAY_A ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
187 }
188
189 if ( is_array( $client_contacts ) ) {
190 foreach ( $client_contacts as $contact ) {
191 static::$enable_widgets[ 'contact_' . $contact['contact_id'] ] = true;
192 }
193 }
194 $values = static::$enable_widgets;
195
196 /**
197 * Unset unwanted Widgets
198 *
199 * Contains the list of enabled widgets and allows user to unset unwanted widgets.
200 *
201 * @param array $values Array containing enabled widgets.
202 * @param int $dashboard_siteid Child site (Operations) ID.
203 *
204 * @since 4.3
205 */
206 $values = apply_filters( 'mainwp_clients_overview_enabled_widgets', $values, null );
207 static::$enable_widgets = array_merge( static::$enable_widgets, $values );
208
209 // Load the Overview widget.
210 if ( static::$enable_widgets['overview'] ) {
211 MainWP_UI::add_widget_box( 'overview', array( MainWP_Client_Overview_Info::get_class_name(), 'render' ), $page, array( -1, -1, 3, 40 ) );
212 }
213
214 // Load the Notes widget.
215 if ( static::$enable_widgets['note'] ) {
216 MainWP_UI::add_widget_box( 'note', array( MainWP_Client_Overview_Note::get_class_name(), 'render' ), $page, array( -1, -1, 3, 40 ) );
217 }
218
219 // Load the Websites widget.
220 if ( static::$enable_widgets['websites'] ) {
221 MainWP_UI::add_widget_box( 'websites', array( MainWP_Client_Overview_Sites::get_class_name(), 'render' ), $page, array( -1, -1, 6, 40 ) );
222 }
223
224 // Load the Info widget.
225 if ( static::$enable_widgets['fields_info'] ) {
226 MainWP_UI::add_widget_box( 'fields_info', array( MainWP_Client_Overview_Custom_Info::get_class_name(), 'render' ), $page, array( -1, -1, 6, 30 ) );
227 }
228
229 // Load the Non-MainWP Changes widget.
230 if ( static::$enable_widgets['non_mainwp_changes'] ) {
231 MainWP_UI::add_widget_box( 'non_mainwp_changes', array( MainWP_Site_Actions::get_class_name(), 'render' ), $page, array( -1, -1, 6, 30 ) );
232 }
233
234 // Load the Recent Posts widget.
235 if ( static::$enable_widgets['recent_posts'] ) {
236 MainWP_UI::add_widget_box( 'recent_posts', array( MainWP_Recent_Posts::get_class_name(), 'render' ), $page, array( -1, -1, 6, 30 ) );
237 }
238
239 // Load the Recent Pages widget.
240 if ( static::$enable_widgets['recent_pages'] ) {
241 MainWP_UI::add_widget_box( 'recent_pages', array( MainWP_Recent_Pages::get_class_name(), 'render' ), $page, array( -1, -1, 6, 30 ) );
242 }
243
244 if ( is_array( $client_contacts ) ) {
245 foreach ( $client_contacts as $contact ) {
246 if ( isset( static::$enable_widgets[ 'contact_' . $contact['contact_id'] ] ) && static::$enable_widgets[ 'contact_' . $contact['contact_id'] ] ) {
247 $contact_widget = new MainWP_Client_Overview_Contacts();
248 $contact_widget->contact = $contact;
249 MainWP_UI::add_widget_box( 'contact_' . $contact['contact_id'], array( $contact_widget, 'render' ), $page, array( -1, -1, 3, 30 ) );
250 }
251 }
252 }
253
254 $i = 1;
255 foreach ( $extMetaBoxs as $metaBox ) {
256 $enabled = true;
257 if ( isset( $metaBox['plugin'] ) ) {
258 $name = basename( $metaBox['plugin'], '.php' );
259 if ( isset( static::$enable_widgets[ $name ] ) && ! static::$enable_widgets[ $name ] ) {
260 $enabled = false;
261 }
262 }
263
264 $id = isset( $metaBox['id'] ) ? $metaBox['id'] : $i++;
265 $id = 'advanced-' . $id;
266
267 $layout = ! empty( $metaBox['layout'] ) && is_array( $metaBox['layout'] ) ? $metaBox['layout'] : array( -1, -1, 6, 30 );
268
269 if ( $enabled ) {
270 MainWP_UI::add_widget_box( $id, $metaBox['callback'], $page, $layout );
271 }
272 }
273 }
274
275 /**
276 * Method on_show_page()
277 *
278 * When the page loads render the body content.
279 */
280 public function on_show_page() {
281 if ( ! \mainwp_current_user_can( 'dashboard', 'manage_clients' ) && ! \mainw\mainwp_current_user_can( 'dashboard', 'access_client_dashboard' ) ) {
282 \mainwp_do_not_have_permissions( esc_html__( 'client dashboard', 'mainwp' ) );
283 return;
284 }
285
286 /**
287 * Screen layout columns array.
288 *
289 * @global object
290 */
291 global $screen_layout_columns;
292
293 MainWP_Client::render_header( 'overview' );
294
295 static::render_dashboard_body();
296 ?>
297 </div>
298 <?php
299 }
300
301 /**
302 * Method render_dashboard_body()
303 *
304 * Render the Dashboard Body content.
305 */
306 public static function render_dashboard_body() {
307
308 MainWP_Ui_Manage_Widgets_Layout::render_modal_save_layout();
309
310 $screen = get_current_screen();
311 ?>
312 <div class="mainwp-primary-content-wrap">
313 <div class="ui segment">
314 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'client-widgets' ) ) : ?>
315 <div class="ui message" style="margin:1em;">
316 <i class="close icon mainwp-notice-dismiss" notice-id="client-widgets"></i>
317 <?php /* translators: 1: bulb emoji, 2: cog icon, 3: layout icon */ printf( esc_html__( '%1$s Tip: You can drag and drop widgets to reorder your dashboard, use Page Settings (%2$s) to show or hide widgets, and use Layout (%3$s) in the header to save and load your widget layouts.', 'mainwp' ), '<em data-emoji=":bulb:" class="small"></em>', '<i class="cog fitted icon"></i>', '<i class="all border fitted icon"></i>' ); ?>
318 </div>
319 <?php endif; ?>
320 <div id="mainwp-message-zone" class="ui message" style="display:none;"></div>
321 <?php do_action( 'mainwp_module_log_render_db_update_notice' ); ?>
322 <?php do_action( 'mainwp_module_log_render_db_size_notice', 300, 'client_overview' ); ?>
323 <?php
324 /**
325 * Action: mainwp_before_overview_widgets
326 *
327 * Fires at the top of the Operations page (before first widget).
328 *
329 * @since 4.3
330 */
331 do_action( 'mainwp_before_overview_widgets', 'clients' );
332 ?>
333 <div id="mainwp-grid-wrapper" class="gridster">
334 <div id="mainwp-widgets-placeholder" class="ui page dimmer">
335 <div class="ui double text loader"><?php esc_html_e( 'Loading...', 'mainwp' ); ?></div>
336 </div>
337 <script>
338 jQuery( document ).ready( function () {
339 jQuery('#mainwp-widgets-placeholder').dimmer('show');
340 });
341 </script>
342 <?php MainWP_UI::do_widget_boxes( $screen->id ); ?>
343 </div>
344 <?php
345 /**
346 * Action: 'mainwp_after_overview_widgets'
347 *
348 * Fires at the bottom of the Operations page (after the last widget).
349 *
350 * @since 4.3
351 */
352 do_action( 'mainwp_after_overview_widgets', 'clients' );
353 ?>
354 </div>
355 <script type="text/javascript">
356 jQuery( document ).ready( function( $ ) {
357
358 jQuery( '.mainwp-widget .mainwp-dropdown-tab .item' ).tab();
359
360 mainwp_clients_overview_screen_options = function () {
361 jQuery( '#mainwp-clients-overview-screen-options-modal' ).modal( {
362 allowMultiple: true,
363 onHide: function () {
364 }
365 } ).modal( 'show' );
366 return false;
367 };
368 jQuery('#reset-clients-overview-settings').on('click', function () {
369 mainwp_confirm(__('Are you sure?'), function(){
370 jQuery('.mainwp_hide_wpmenu_checkboxes input[name="mainwp_show_widgets[]"]').prop('checked', true);
371 jQuery('input[name=reset_client_overview_settings]').attr('value', 1);
372 jQuery('#submit-client-overview-settings').click();
373 }, false, false, true);
374 return false;
375 });
376 } );
377 </script>
378 <div class="ui modal" id="mainwp-clients-overview-screen-options-modal">
379 <i class="close icon"></i>
380 <div class="header"><?php esc_html_e( 'Page Settings', 'mainwp' ); ?></div>
381 <div class="content ui form">
382 <?php
383 /**
384 * Action: mainwp_clients_overview_screen_options_top
385 *
386 * Fires at the top of the Sceen Options modal on the Operations page.
387 *
388 * @since 4.1
389 */
390 do_action( 'mainwp_clients_overview_screen_options_top' );
391 ?>
392 <form method="POST" action="" name="mainwp_clients_overview_screen_options_form" id="mainwp-clients-overview-screen-options-form">
393 <?php MainWP_UI::generate_wp_nonce( 'mainwp-admin-nonce' ); ?>
394 <input type="hidden" name="wp_scr_options_nonce" value="<?php echo esc_attr( wp_create_nonce( 'MainWPClientsScrOptions' ) ); ?>" />
395 <?php static::render_screen_options( false ); ?>
396 <?php
397 /**
398 * Action: mainwp_clients_overview_screen_options_bottom
399 *
400 * Fires at the bottom of the Sceen Options modal on the Operations page.
401 *
402 * @since 4.1
403 */
404 do_action( 'mainwp_clients_overview_screen_options_bottom' );
405 ?>
406 </div>
407 <div class="actions">
408 <div class="ui two columns grid">
409 <div class="left aligned column">
410 <span data-tooltip="<?php esc_attr_e( 'Resets the page to its original layout and reinstates relocated widgets.', 'mainwp' ); ?>" data-inverted="" data-position="top left"><input type="button" class="ui button" name="reset" id="reset-clients-overview-settings" value="<?php esc_attr_e( 'Reset Page', 'mainwp' ); ?>" /></span>
411 </div>
412 <div class="ui right aligned column">
413 <input type="submit" class="ui green button" id="submit-client-overview-settings" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>" />
414 </div>
415 </div>
416 </div>
417
418 <input type="hidden" name="reset_client_overview_settings" value="" />
419 </form>
420 </div>
421 </div>
422 <?php
423 }
424
425 /**
426 * Method render_screen_options()
427 *
428 * Render Page Settings.
429 *
430 * @return void Render Page Settings html.
431 */
432 public static function render_screen_options() { // phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated.
433
434 $default_widgets = array(
435 'overview' => esc_html__( 'Overview', 'mainwp' ),
436 'note' => esc_html__( 'Notes', 'mainwp' ),
437 'fields_info' => esc_html__( 'Addition Info', 'mainwp' ),
438 'websites' => esc_html__( 'Websites', 'mainwp' ),
439 'recent_posts' => esc_html__( 'Recent Posts', 'mainwp' ),
440 'recent_pages' => esc_html__( 'Recent Pages', 'mainwp' ),
441 'non_mainwp_changes' => esc_html__( 'Network Activity', 'mainwp' ),
442 );
443
444 if ( isset( $_GET['client_id'] ) && ! empty( $_GET['client_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
445 $client_contacts = MainWP_DB_Client::instance()->get_wp_client_contact_by( 'client_id', intval( $_GET['client_id'] ), ARRAY_A ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
446 if ( $client_contacts ) {
447 foreach ( $client_contacts as $contact ) {
448 $default_widgets[ 'contact_' . $contact['contact_id'] ] = esc_html( $contact['contact_name'] );
449
450 }
451 }
452 }
453
454 $custom_opts = array();
455 /**
456 * Filter: mainwp_clients_widgets_screen_options
457 *
458 * Filters available widgets on the Operations page allowing users to unset unwanted widgets.
459 *
460 * @since 4.0
461 */
462 $custom_opts = apply_filters( 'mainwp_clients_widgets_screen_options', $custom_opts );
463
464 if ( is_array( $custom_opts ) && ! empty( $custom_opts ) ) {
465 $default_widgets = array_merge( $default_widgets, $custom_opts );
466 }
467
468 $show_widgets = get_user_option( 'mainwp_clients_show_widgets' );
469 if ( ! is_array( $show_widgets ) ) {
470 $show_widgets = array();
471 }
472
473 /**
474 * Action: mainwp_screen_options_modal_top
475 *
476 * Fires at the top of the Page Settings modal element.
477 *
478 * @since 4.1
479 */
480 do_action( 'mainwp_screen_options_modal_top' );
481 ?>
482 <?php if ( isset( $_GET['page'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized ?>
483 <div class="ui grid field">
484 <label class="six wide column"><?php esc_html_e( 'Show widgets', 'mainwp' ); ?></label>
485 <div class="ten wide column" <?php echo 'data-tooltip="' . esc_attr__( 'Select widgets that you want to hide in the MainWP Operations page.', 'mainwp' ) . '"'; ?> data-inverted="" data-position="top left">
486 <ul class="mainwp_hide_wpmenu_checkboxes">
487 <?php
488 foreach ( $default_widgets as $name => $title ) {
489 $_selected = '';
490 if ( ! isset( $show_widgets[ $name ] ) || 1 === (int) $show_widgets[ $name ] ) {
491 $_selected = 'checked';
492 }
493 ?>
494 <li>
495 <div class="ui checkbox">
496 <input type="checkbox" id="mainwp_show_widget_<?php echo esc_attr( $name ); ?>" name="mainwp_show_widgets[]" <?php echo esc_html( $_selected ); ?> value="<?php echo esc_attr( $name ); ?>">
497 <label for="mainwp_show_widget_<?php echo esc_attr( $name ); ?>" ><?php echo esc_html( $title ); ?></label>
498 </div>
499 <input type="hidden" name="mainwp_widgets_name[]" value="<?php echo esc_attr( $name ); ?>">
500 </li>
501 <?php
502 }
503 ?>
504 </ul>
505 </div>
506 </div>
507 <?php endif; ?>
508 <?php
509 /**
510 * Action: mainwp_screen_options_modal_bottom
511 *
512 * Fires at the bottom of the Page Settings modal element.
513 *
514 * @since 4.1
515 */
516 do_action( 'mainwp_screen_options_modal_bottom' );
517 }
518
519
520 /**
521 * Method mainwp_help_content()
522 *
523 * Creates the MainWP Help Documentation List for the help component in the sidebar.
524 */
525 public static function mainwp_help_content() {
526 if ( isset( $_GET['page'] ) && 'ManageClients' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
527 ?>
528 <p><?php esc_html_e( 'If you need help with your MainWP Dashboard, please review following help documents', 'mainwp' ); ?></p>
529 <div class="ui list">
530 <div class="item"><i class="external alternate icon"></i> <a href="https://docs.mainwp.com/clients/manage-clients" target="_blank">Manage Clients</a></div> <?php // NOSONAR - noopener - open safe. ?>
531 <div class="item"><i class="external alternate icon"></i> <a href="https://docs.mainwp.com/clients/manage-clients#create-a-new-client" target="_blank">Create a new Client</a></div> <?php // NOSONAR - noopener - open safe. ?>
532 <div class="item"><i class="external alternate icon"></i> <a href="https://docs.mainwp.com/clients/manage-clients#update-a-client" target="_blank">Update a Client</a></div> <?php // NOSONAR - noopener - open safe. ?>
533 <div class="item"><i class="external alternate icon"></i> <a href="https://docs.mainwp.com/clients/manage-clients#update-a-client" target="_blank">Delete a Client</a></div> <?php // NOSONAR - noopener - open safe. ?>
534 <div class="item"><i class="external alternate icon"></i> <a href="https://docs.mainwp.com/clients/manage-clients#customize-the-manage-clients-table" target="_blank">Customize the Manage Clients table</a></div> <?php // NOSONAR - noopener - open safe. ?>
535 <div class="item"><i class="external alternate icon"></i> <a href="https://docs.mainwp.com/clients/manage-clients#client-card" target="_blank">Client Card (View Client)</a></div> <?php // NOSONAR - noopener - open safe. ?>
536 <div class="item"><i class="external alternate icon"></i> <a href="https://docs.mainwp.com/clients/manage-clients#client-fields" target="_blank">Client Fields</a></div> <?php // NOSONAR - noopener - open safe. ?>
537 <?php
538 /**
539 * Action: mainwp_clients_overview_help_item
540 *
541 * Fires at the bottom of the help articles list in the Help sidebar on the Clients page.
542 *
543 * Suggested HTML markup:
544 *
545 * <div class="item"><a href="Your custom URL">Your custom text</a></div>
546 *
547 * @since 4.3
548 */
549 do_action( 'mainwp_clients_overview_help_item' );
550 ?>
551 </div>
552 <?php
553 }
554 }
555 }
556