admin管理员组文章数量:1312895
I want this code to work only for Authors AND Contributors
Please modify this code for me using
if ( ! current_user_can( 'manage_options' ) ) {
//Hide Menu Options in Admin Section
add_action('admin_menu','wf_cli_remove_admin_menu');
function wf_cli_remove_admin_menu()
{
remove_menu_page('index.php');
remove_menu_page('separator1');
remove_menu_page('separator2');
remove_menu_page('edit-comments.php');
remove_menu_page('edit.php?post_type=tdb_templates');
remove_menu_page('tools.php');
}
I want this code to work only for Authors AND Contributors
Please modify this code for me using
if ( ! current_user_can( 'manage_options' ) ) {
//Hide Menu Options in Admin Section
add_action('admin_menu','wf_cli_remove_admin_menu');
function wf_cli_remove_admin_menu()
{
remove_menu_page('index.php');
remove_menu_page('separator1');
remove_menu_page('separator2');
remove_menu_page('edit-comments.php');
remove_menu_page('edit.php?post_type=tdb_templates');
remove_menu_page('tools.php');
}
Share
Improve this question
edited Jan 4, 2021 at 2:05
UsmanSwift
asked Jan 3, 2021 at 18:25
UsmanSwiftUsmanSwift
13 bronze badges
1
- developer.wordpress/reference/functions/get_role – Mike Aron Commented Jan 3, 2021 at 20:46
1 Answer
Reset to default 0Here you go, and remember, this assumes that your function was already working (I did not check that it was), and if it was, then just wrap like this:
<?php
add_action( 'admin_menu', 'wf_cli_remove_admin_menu' );
function wf_cli_remove_admin_menu() {
$wf_user = wp_get_current_user();
$wf_roles = array( 'contributor', 'author' );
if( array_intersect( $wf_roles, $wf_user->roles ) ) :
remove_menu_page( 'index.php' );
remove_menu_page( 'separator1' );
remove_menu_page( 'separator2' );
remove_menu_page( 'edit-comments.php' );
remove_menu_page( 'edit.php?post_type=tdb_templates' );
remove_menu_page( 'tools.php' );
endif;
}
?>
The answer is quite simple to find... ..probably multiple answers on WPStack and then there's this: https://developer.wordpress/reference/functions/current_user_can/#comment-4083
本文标签: user rolesI want this code to work only for Authors AND Contributors
版权声明:本文标题:user roles - I want this code to work only for Authors AND Contributors 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741867758a2402011.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论