Could we help you? Please click the banners. We are young and desperately need the money
In WordPress, ensuring the security and integrity of your website is paramount. One aspect of this is controlling access to various admin pages. While WordPress provides robust user roles and capabilities, sometimes you need to hide specific admin pages from users who don't have the privilege to manage all options. In this article, we'll explore a practical approach to hide certain admin pages in WordPress for users with restricted permissions.
WordPress offers several user roles such as Administrator, Editor, Author, Contributor, and Subscriber. Each role comes with predefined capabilities, allowing users to perform certain actions within the WordPress dashboard. The 'manage_options' capability, typically associated with the Administrator role, grants users the authority to access and modify all settings and options within WordPress.
To hide specific admin pages for users who do not have the 'manage_options' capability, we can utilize a simple PHP function hooked into the 'admin_menu' action hook. Let's break down the example code provided:
<?php
function remove_admin_pages()
{
if (current_user_can('manage_options')) {
return;
}
remove_menu_page('edit.php');
remove_menu_page('tools.php');
remove_menu_page('plugins.php');
remove_submenu_page('themes.php', 'themes.php');
}
add_action('admin_menu', 'remove_admin_pages');
?>
Explanation:
You can customize this code snippet to suit your specific requirements. Simply replace the menu page slugs ('edit.php', 'tools.php', 'plugins.php', etc.) with the slugs of the pages you want to hide. You can find these slugs by inspecting the URLs of the admin pages.