Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
i think simply register the widget area like we do in the theme and it should work.. –  Sisir Nov 14 '11 at 15:37
add comment

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
Thank you. Almost there, but the toggle button is not working. All the widgets –  Omar Abid Nov 15 '11 at 12:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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