true, 'note' => true, 'fields_info' => true, 'websites' => true, 'recent_posts' => true, 'recent_pages' => true, 'non_mainwp_changes' => true, ); /** * Current page. * * @static * @var string $page Current page. */ public static $page; /** * Check if there is a session, * if there isn't one create it. * * @return static::singlton Overview Page Session. * * @uses \MainWP\Dashboard\MainWP_Overview */ public static function instance() { if ( null === static::$instance ) { static::$instance = new self(); } return static::$instance; } /** * MainWP_Overview constructor. * * Run each time the class is called. */ public function __construct() { add_filter( 'screen_layout_columns', array( &$this, 'on_screen_layout_columns' ), 10, 2 ); add_action( 'mainwp_help_sidebar_content', array( &$this, 'mainwp_help_content' ) ); } /** * Set the number of page coumns. * * @param mixed $columns Number of Columns. * @param mixed $screen Screen size. * * @return int $columns Number of desired page columns. */ public function on_screen_layout_columns( $columns, $screen ) { if ( $screen === static::$page ) { $columns[ static::$page ] = 3; } return $columns; } /** * Method on_load_page() * * Run on page load. * * @param mixed $page Page name. */ public static function on_load_page( $page ) { static::$page = $page; $val = get_user_option( 'screen_layout_' . $page ); if ( ! $val ) { global $current_user; update_user_option( $current_user->ID, 'screen_layout_' . $page, 2, true ); } wp_enqueue_script( 'common' ); wp_enqueue_script( 'wp-lists' ); wp_enqueue_script( 'postbox' ); wp_enqueue_script( 'dashboard' ); wp_enqueue_script( 'widgets' ); static::add_meta_boxes( $page ); add_filter( 'mainwp_header_actions_right', array( static::get_class_name(), 'screen_options' ), 10, 2 ); } /** * Method screen_options() * * Create Page Settings button. * * @param mixed $input Page Settings button HTML. * * @return mixed Page Settings button. */ public static function screen_options( $input ) { return $input . ' '; } /** * Method add_meta_boxes() * * Add MainWP Overview Page Widgets. * * @param array $page Current page. * * @uses \MainWP\Dashboard\MainWP_System_Handler::apply_filters() * @uses \MainWP\Dashboard\MainWP_System_Utility::get_current_wpid() * @uses \MainWP\Dashboard\MainWP_UI::add_widget_box() * @uses \MainWP\Dashboard\MainWP_Connection_Status::get_class_name() * @uses \MainWP\Dashboard\MainWP_Recent_Pages::get_class_name() * @uses \MainWP\Dashboard\MainWP_Recent_Posts::get_class_name() * @uses \MainWP\Dashboard\MainWP_Security_Issues_Widget::get_class_name() * @uses \MainWP\Dashboard\MainWP_Updates_Overview::get_class_name() */ 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. /** * Get getmetaboxes * * Adds metaboxes (widgets) to the Overview page. * * @since 4.3 */ $extMetaBoxs = array(); $extMetaBoxs = apply_filters( 'mainwp_clients_getmetaboxes', $extMetaBoxs ); foreach ( $extMetaBoxs as $box ) { if ( isset( $box['plugin'] ) ) { $name = basename( $box['plugin'], '.php' ); static::$enable_widgets[ $name ] = true; } elseif ( ! empty( $box['widget_id'] ) ) { static::$enable_widgets[ $box['widget_id'] ] = true; } } $client_contacts = array(); if ( isset( $_GET['client_id'] ) && ! empty( $_GET['client_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $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 } if ( is_array( $client_contacts ) ) { foreach ( $client_contacts as $contact ) { static::$enable_widgets[ 'contact_' . $contact['contact_id'] ] = true; } } $values = static::$enable_widgets; /** * Unset unwanted Widgets * * Contains the list of enabled widgets and allows user to unset unwanted widgets. * * @param array $values Array containing enabled widgets. * @param int $dashboard_siteid Child site (Overview) ID. * * @since 4.3 */ $values = apply_filters( 'mainwp_clients_overview_enabled_widgets', $values, null ); static::$enable_widgets = array_merge( static::$enable_widgets, $values ); // Load the Overview widget. if ( static::$enable_widgets['overview'] ) { MainWP_UI::add_widget_box( 'overview', array( MainWP_Client_Overview_Info::get_class_name(), 'render' ), $page, array( -1, -1, 3, 40 ) ); } // Load the Notes widget. if ( static::$enable_widgets['note'] ) { MainWP_UI::add_widget_box( 'note', array( MainWP_Client_Overview_Note::get_class_name(), 'render' ), $page, array( -1, -1, 3, 40 ) ); } // Load the Websites widget. if ( static::$enable_widgets['websites'] ) { MainWP_UI::add_widget_box( 'websites', array( MainWP_Client_Overview_Sites::get_class_name(), 'render' ), $page, array( -1, -1, 6, 40 ) ); } // Load the Info widget. if ( static::$enable_widgets['fields_info'] ) { MainWP_UI::add_widget_box( 'fields_info', array( MainWP_Client_Overview_Custom_Info::get_class_name(), 'render' ), $page, array( -1, -1, 6, 30 ) ); } // Load the Non-MainWP Changes widget. if ( static::$enable_widgets['non_mainwp_changes'] ) { MainWP_UI::add_widget_box( 'non_mainwp_changes', array( MainWP_Site_Actions::get_class_name(), 'render' ), $page, array( -1, -1, 6, 30 ) ); } // Load the Recent Posts widget. if ( static::$enable_widgets['recent_posts'] ) { MainWP_UI::add_widget_box( 'recent_posts', array( MainWP_Recent_Posts::get_class_name(), 'render' ), $page, array( -1, -1, 6, 30 ) ); } // Load the Recent Pages widget. if ( static::$enable_widgets['recent_pages'] ) { MainWP_UI::add_widget_box( 'recent_pages', array( MainWP_Recent_Pages::get_class_name(), 'render' ), $page, array( -1, -1, 6, 30 ) ); } if ( is_array( $client_contacts ) ) { foreach ( $client_contacts as $contact ) { if ( isset( static::$enable_widgets[ 'contact_' . $contact['contact_id'] ] ) && static::$enable_widgets[ 'contact_' . $contact['contact_id'] ] ) { $contact_widget = new MainWP_Client_Overview_Contacts(); $contact_widget->contact = $contact; MainWP_UI::add_widget_box( 'contact_' . $contact['contact_id'], array( $contact_widget, 'render' ), $page, array( -1, -1, 3, 30 ) ); } } } $i = 1; foreach ( $extMetaBoxs as $metaBox ) { $enabled = true; if ( isset( $metaBox['plugin'] ) ) { $name = basename( $metaBox['plugin'], '.php' ); if ( isset( static::$enable_widgets[ $name ] ) && ! static::$enable_widgets[ $name ] ) { $enabled = false; } } $id = isset( $metaBox['id'] ) ? $metaBox['id'] : $i++; $id = 'advanced-' . $id; $layout = ! empty( $metaBox['layout'] ) && is_array( $metaBox['layout'] ) ? $metaBox['layout'] : array( -1, -1, 6, 30 ); if ( $enabled ) { MainWP_UI::add_widget_box( $id, $metaBox['callback'], $page, $layout ); } } } /** * Method on_show_page() * * When the page loads render the body content. */ public function on_show_page() { if ( ! \mainwp_current_user_can( 'dashboard', 'manage_clients' ) && ! \mainw\mainwp_current_user_can( 'dashboard', 'access_client_dashboard' ) ) { \mainwp_do_not_have_permissions( esc_html__( 'client dashboard', 'mainwp' ) ); return; } /** * Screen layout columns array. * * @global object */ global $screen_layout_columns; MainWP_Client::render_header( 'overview' ); static::render_dashboard_body(); ?>