• Hello all,

    I’m trying to get a list of all of the dashboard widgets on my options page.

    I know you can do the following:

    add_action('wp_dashboard_setup', 'remove_dashboard_widgets' );
    function remove_dashboard_widgets() {
    	global $wp_meta_boxes;
    
    	foreach($wp_meta_boxes['dashboard'] as $m) {
    		print_r($m);
    	}
    }

    This seems to only work on the dashboard, not globally across all pages.

    Is there a nice way of retrieving the same information on another page?

    Many thanks in advance.

    Dave

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Dave Redfern

    (@daveredfern)

    Can anyone help with this query please?

    I have been writing a plugin that will let you manage your dashboard widgets for different roles. It is not done yet but I will hopefully be releasing it in the next couple of months. The way that I get the list of registered dashboard widgets is this little snippet.

    function manage_dash_setup($arg1) {
    	global $wp_meta_boxes, $wpdb;
    	if (current_user_can('administrator') && is_array($wp_meta_boxes['dashboard'])) {
              update_option($wpdb->prefix.'dash_widget_manager_registered_widgets', $wp_meta_boxes['dashboard']);
    	}
    }
    
    add_action('wp_dashboard_setup', 'manage_dash_setup', 100);

    Put this in your functions.php file or a plugin and it will set an option called $wpdb->prefix.’dash_widget_manager_registered_widgets’ that will contain the array of registered dashboard widgets. It will get updated whenever you go to the dashboard as an admin user and you can use it anywhere you’d like. This is the best solution Ive been able to find.

    I decided to move my plugin along after needing it for something last week and have published it to the plugin directory. You can find it here: http://wordpress.org/extend/plugins/dash-widget-manager/. Don’t know if this will help with what you are trying to do but it will give you a working example of the snippet I posted above.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to get a list of all dashboard widgets’ is closed to new replies.