0

I'm looking to put widgets in my plug-in settings page like the ones in the WordPress Dashboard.

The action to register the widget is

add_action('wp_dashboard_setup', 'register_widgets' );

I wonder if it's possible to do the same for your own settings pages.

1
  • i think simply register the widget area like we do in the theme and it should work..
    – Sisir
    Nov 14, 2011 at 15:37

1 Answer 1

2

You would call:

add_meta_box( $widget_id, $widget_name, $callback, $screen->id, $location, $priority );

Where the screen ID is obtained via:

$screen = get_current_screen();

Then display each location e.g. :

do_meta_boxes( $screen->id, 'column3', '' );

Here's the dashboard function that displays the dashboard:

function wp_dashboard() {
    global $screen_layout_columns;

    $screen = get_current_screen();

    $hide2 = $hide3 = $hide4 = '';
    switch ( $screen_layout_columns ) {
        case 4:
            $width = 'width:24.5%;';
            break;
        case 3:
            $width = 'width:32.67%;';
            $hide4 = 'display:none;';
            break;
        case 2:
            $width = 'width:49%;';
            $hide3 = $hide4 = 'display:none;';
            break;
        default:
            $width = 'width:98%;';
            $hide2 = $hide3 = $hide4 = 'display:none;';
    }
?>
<div id="dashboard-widgets" class="metabox-holder">
<?php
    echo "\t<div class='postbox-container' style='$width'>\n";
    do_meta_boxes( $screen->id, 'normal', '' );

    echo "\t</div><div class='postbox-container' style='{$hide2}$width'>\n";
    do_meta_boxes( $screen->id, 'side', '' );

    echo "\t</div><div class='postbox-container' style='{$hide3}$width'>\n";
    do_meta_boxes( $screen->id, 'column3', '' );

    echo "\t</div><div class='postbox-container' style='{$hide4}$width'>\n";
    do_meta_boxes( $screen->id, 'column4', '' );
?>
</div></div>

<form style="display:none" method="get" action="">
    <p>
<?php
    wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
    wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
?>
    </p>
</form>

<?php
}

For further reference, look at wp-admin/index.php and the included dashboard files.

1
  • Thank you. Almost there, but the toggle button is not working. All the widgets
    – Omar Abid
    Nov 15, 2011 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.