WordPress.org

Forums

multiple dashboard (7 posts)

  1. gaddoz
    Member
    Posted 2 years ago #

    Hi all

    I find the dashboard ui really cool and useful.
    I'm wondering if there is some way to get my plugin to reuse the ui for giving my plugin backend a backend with a custom secondary dashboard.
    it would be really cool to have the chance to setup one or more dashboards being able to setup widgets to show on dashboard-1 and other widgets on dashboard-2.

    anyone had my same idea and solved some way?

  2. Micah Wood
    Member
    Posted 2 years ago #

    You should be able to just use the add_menu_page() and then add something like the following code as the page output:

    <?php /** Load WordPress dashboard API */
    require_once(ABSPATH . 'wp-admin/includes/dashboard.php');
    wp_dashboard_setup(); ?>
    <div class="wrap">
    <?php screen_icon(); ?>
    <h2><?php echo esc_html( __('My Dashboard') ); ?></h2>
    <div id="dashboard-widgets-wrap">
    <?php wp_dashboard(); ?>
    <div class="clear"></div>
    </div><!-- dashboard-widgets-wrap -->
    </div><!-- wrap -->

    Just make sure you use your page hook to add the following:

    wp_enqueue_script( 'dashboard' );
    wp_admin_css( 'dashboard' );

    Basically, just look at the /wp-admin/index.php page to get an idea of what you need to do. That is where the code above came from. I just stripped out the non-essentials.

    Then, you should be able to detect what page you are on before adding your dashboard widgets.

  3. gaddoz
    Member
    Posted 2 years ago #

    Thanks Micha!

    but then i get an exact copy of the dashboard, i guess,
    and all the widgets will show on each dashboard..
    what about having the option to decide which widget goes on which dashboard?

    any clue?

  4. bcworkz
    Member
    Posted 2 years ago #

    The dashboard functions were never intended to support multiple dashboards. The pertinent settings are stored in a unique set of globals and DB options. For starters, you would need to recreate the first couple functions in dashboard.php, this time adding different widgets, and storing data in different globals and options. Otherwise what the user does to one dashboard will crosstalk with the other dashboard.

    There may be other ramifications that I haven't foreseen that will need to be dealt with as well.

  5. gaddoz
    Member
    Posted 2 years ago #

    managed recreating the following functions:

    wp_dashboard to custom_dashboard
    wp_add_dashboard_widget to custom_add_dashboard_widget
    wp_dashboard_setup to custom_dashboard_setup

    will test it deeper but looks like is working fine!

  6. Micah Wood
    Member
    Posted 2 years ago #

    You could actually use the built in functions to create multiple dashboards. You will have to clear out the dashboard widgets and add your custom widgets on your custom dashboard.

    Just clear out $wp_meta_boxes['dashboard'] and use the wp_add_dashboard_widget() function to add your own, but only on your custom dashboard.
    http://codex.wordpress.org/Dashboard_Widgets_API

  7. bcworkz
    Member
    Posted 2 years ago #

    @Micah,
    Doing it that way, you still only have the one dashboard, except redefined now as the custom one. I suppose you can redefine each dashboard on the fly based on which menu page is requested. Seems inefficient, but so is maintaining identical function sets for each dashboard page.

    One also needs to manage the user's page state for each page or else their pages will revert to default on every load.

    Either approach is less than ideal, there's a plugin idea here that could be developed-- Combine the Settings and widget APIs such that widgets can be placed on any settings page without conflict.

Topic Closed

This topic has been closed to new replies.

About this Topic