Php 在WordPress中添加管理菜单分隔符
我正在尝试创建一个管理菜单分隔符,允许您将它们与代码一起放入。这就是功能:Php 在WordPress中添加管理菜单分隔符,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,我正在尝试创建一个管理菜单分隔符,允许您将它们与代码一起放入。这就是功能: 功能添加\管理\菜单\分隔符($position){ 全球$菜单; $index=0; foreach($菜单作为$offset=>$section){ if(substr($section[2],0,9)=='separator') $index++; 如果($offset>=$position){ $menu[$position]=数组(“”,'read','separator{$index},“”,'wp-menu
功能添加\管理\菜单\分隔符($position){
全球$菜单;
$index=0;
foreach($菜单作为$offset=>$section){
if(substr($section[2],0,9)=='separator')
$index++;
如果($offset>=$position){
$menu[$position]=数组(“”,'read','separator{$index},“”,'wp-menu-separator');
打破
}
}
ksort($菜单);
}
下面是添加操作位
add_action('admin_init','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
您应该挂接
管理菜单
:
add_action('admin_menu','admin_menu_separator');
并使用低于220的代码。我在系统中得到的最大偏移量是99
检查以处理管理菜单。
它出现在这个WPSE问题中:您可以简单地在functions.php中添加它
add_action('admin_menu', function () {
global $menu;
$menu[49] = ['', 'read', '', '', 'wp-menu-separator'];
});
其中49是分隔符位置,您必须记住,如果菜单元素的位置相同,分隔符位置可以替换它。我猜您没有应用数组,因此为什么ksort()
报告已给出null
。。由于foreach循环尚未处理任何数组,因此它将生成警告