我最近试图通过编写插件对仪表板小部件进行重新排序。我做到了这一点:
使用以下代码:<?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\');
正如您在我制作的屏幕截图中所看到的,该插件似乎只查看$left_column_widgets 和$right_column_widgets, 这会导致错误(因为“d”不是有效的小部件段塞)。有没有办法解决这个问题?干杯