我正在尝试创建一个管理菜单分隔符,允许您将它们与代码一起放入。这是功能:
function add_admin_menu_separator($position) {
global $menu;
$index = 0;
foreach($menu as $offset => $section) {
if (substr($section[2],0,9)=='separator')
$index++;
if ($offset>=$position) {
$menu[$position] = array('','read',"separator{$index}",'','wp-menu-separator');
break;
}
}
ksort( $menu );
}
添加操作位如下
add_action('admin_init','admin_menu_separator');
function admin_menu_separator() {
add_admin_menu_separator(220);
}
它工作正常,但在重新排列菜单时会在 WordPress 中产生以下错误:
> Warning: Invalid argument supplied for foreach() in /home/user/public_html/wp-creation.com/wp-content/themes/liquid_theme_0.4_licensed/functions.php on line 174
> Warning: ksort() expects parameter 1 to be array, null given in /home/user/public_html/wp-creation.com/wp-content/themes/liquid_theme_0.4_licensed/functions.php on line 182