Wordpress -删除自定义用户角色的节点



我试图自定义WP用户仪表板,并试图删除/隐藏一些功能,如管理栏链接。

用这段代码,我试图删除所有无用的东西:

add_action( 'admin_bar_menu', 'remove_wp_nodes', 999 );
function remove_wp_nodes() 
{
global $wp_admin_bar; 
$wp_admin_bar->remove_node( 'new-post' );
$wp_admin_bar->remove_node( 'new-link' );
$wp_admin_bar->remove_node( 'new-media' );
$wp_admin_bar->remove_node( 'comments' );
$wp_admin_bar->remove_node( 'new-content' );
$wp_admin_bar->remove_menu( 'new-page' );
$wp_admin_bar->remove_menu( 'new-gry' );
$wp_admin_bar->remove_menu( 'site-name' );
}

但它适用于管理员,而不是我的自定义用户角色,我不知道为什么。即使我添加了条件:

if( user_can( $current_user, "gamer" ) )

如何解决这个问题?"GAMERS"不能访问例如:/wp-admin/edit-comments.phpsection

您可以遵循下面的post hop,它将用于此

https://wordpress.stackexchange.com/questions/350492/hide-from-specific-role-the-top-admin-bar-new-button

替代解决方案

您可以使用WP_Role类,

// get the the role object
$role_object = get_role( $role_name );
// add $cap capability to this role object
$role_object->add_cap( $capability_name );
// remove $cap capability from this role object
$role_object->remove_cap( $capability_name );

因此,为了解决您关于如何使管理员在帖子内容中输入SCRIPT和IFRAME标签的原始问题,您正在寻找'unfiltered_html'功能,该功能在Multisite中仅授予超级管理员。

// get the the role object
$admin_role = get_role( 'administrator' );
// grant the unfiltered_html capability
$admin_role->add_cap( 'unfiltered_html', true );

或者你可以在你的函数中运行一次:

/* Roles & Capabilities */
add_role('professional', 'Professional User', array(
'read' => true, // True allows that capability, False specifically removes it.
'edit_posts' => true,
'delete_posts' => true,
//'edit_published_posts' => true,
//'publish_posts' => true,
//'edit_files' => true,
'upload_files' => true //last in array needs no comma!
));

最新更新