我的 2 个自定义 wordpress 分类法有问题。
我创建了一个名为“kurs”的自定义帖子类型,对于这个自定义帖子类型,我还创建了 2 个自定义分层分类法。这工作正常,直到我想为 2 个分类法添加自定义功能。
我为 2 个功能添加了“功能”参数
第一个分类:
'capabilities' => array(
'manage_terms' => 'manage_location',
'edit_terms' => 'edit_location',
'delete_terms' => 'delete_location',
'assign_terms' => 'assign_location',
)
第二种分类法:
'capabilities' => array(
'manage_terms' => 'manage_typ',
'edit_terms' => 'edit_typ',
'delete_terms' => 'delete_typ',
'assign_terms' => 'assign_typ',
)
然后我使用此功能将所有这些新的自定义功能添加到管理员角色中:
function kurse_role_caps() {
// gets the simple_role role object
$role = get_role('administrator');
// add a new capability
$role->add_cap( 'manage_location', 'edit_location', 'delete_location', 'assign_location', 'manage_typ', 'edit_typ', 'delete_typ', 'assign_typ', true);
}
add simple_role capabilities, priority must be after the initial role definition
add_action('init', 'kurse_role_caps', 11);
但是即使我将参数“show_in_menu”设置为 true,第二个自定义分类法也没有显示在管理菜单中:我的管理菜单的屏幕截图
如果我从第二个分类法中删除自定义功能,它会显示在管理员中:在此处输入图像描述
我在互联网上搜索了这个问题后,没有人遇到过类似的问题。这是我用于自定义帖子类型和 2 个自定义分类法的完整代码的要点:https : //gist.github.com/jeremygrlj/a9319591e3d1940e9ef465f024220e84
请注意,add_cap
只接受一种功能作为字符串,因此您必须循环所有功能。像这样改变你的功能。
function kurse_role_caps() {
// gets the simple_role role object
$role = get_role('administrator');
// add a new capability
$capabilities = array( 'manage_location', 'edit_location', 'delete_location', 'assign_location', 'manage_typ', 'edit_typ', 'delete_typ', 'assign_typ' );
foreach( $capabilities as $cap ) {
$role->add_cap( $cap );
}
}
// add simple_role capabilities, priority must be after the initial role definition
add_action('init', 'kurse_role_caps', 11);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句