I recently tried to reorder the dashboard widgets by writing a plugin. I accomplished this:
with the following code:
<?php
/*
* Plugin Name: Custom Dashboard
* Description: Custom dashboard for Avare sites.
* Author: Avare
* Version: 1.0
*/
function sort_dashboard_widgets() {
$left_column_widgets[] = 'dashboard_right_now';
$left_column_widgets[] = 'dashboard_recent_comments';
$left_column_widgets[] = 'dashboard_incoming_links';
$right_column_widgets[] = 'dashboard_quick_press';
$right_column_widgets[] = 'dashboard_recent_drafts';
$right_column_widgets[] = 'dashboard_primary';
$right_column_widgets[] = 'dashboard_secundary';
// Global the $wp_meta_boxes variable (this will allow us to alter the array)
global $wp_meta_boxes;
// We then unset that part of the array
unset($wp_meta_boxes['dashboard']['normal']['core']);
unset($wp_meta_boxes['dashboard']['side']['core']);
// Then we make a backup of the widget areas
$left_dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
$right_dashboard = $wp_meta_boxes['dashboard']['side']['core'];
// Then we merge them in some sort of way (is this necessary?)
$sorted_left_dashboard = array_merge((array)$left_column_widgets, (array)$left_dashboard);
$sorted_right_dashboard = array_merge((array)$right_column_widgets, (array)$right_dashboard);
// Now we add the sorted widgets back in
$wp_meta_boxes['dashboard']['normal']['core'] = $sorted_left_dashboard;
$wp_meta_boxes['dashboard']['side']['core'] = $sorted_right_dashboard;
}
add_filter('wp_dashboard_setup', 'sort_dashboard_widgets');
As you can see in the screenshot I made, it looks like the plugin only looks at the first letter of $left_column_widgets and $right_column_widgets, which causes the errors (because 'd' is not a valid widget slug). Is there any way to solve this problem?
Cheers