Reputation: 5870
I have created a custom user role "faquser" in my wp site. Now I want to hide contact form 7 menu ( or disable) only for this role. How can I do that? I saw this:
http://contactform7.com/restricting-access-to-the-administration-panel/
But if I do this, then contact form only works for administrator and not for any others. I have also tried to do something like this:
remove_menu_page('admin.php?page=wpcf7');
This did not remove the menu item either.
Upvotes: 5
Views: 10441
Reputation: 401
In order to do this properly you need to write a function that determines which roles you need to remove the menu item for.
remove_menu_page('wpcf7'); // This is the snippet that will remove the contact form 7 menu specifically.
This is an example of a function that does the complete task.
function remove_menu_pages() {
global $user_ID;
if ( !current_user_can( 'publish_posts' ) ) {
remove_menu_page('edit-comments.php'); // Comments
remove_menu_page('edit.php?post_type=page'); // Pages
remove_menu_page('wpcf7'); // Contact Form 7 Menu
}
}
add_action( 'admin_init', 'remove_menu_pages' );
You can get a full list of capabilities of the different roles in WordPress here: https://wordpress.org/support/article/roles-and-capabilities/
I chose "publish_posts" so that all user types below author and who do not have the capability "publish_posts" will not see the contact form 7 menu, or the comments or pages menu items.
Depending on the capabilities you gave your user role "faquser" will determine which capabilities you need to call the function for.
Upvotes: 5