I want to delete user access to some WordPress admin menus .
I use the following code, but this code only removes the menu links.
function remove_admin_menu() {
remove_submenu_page('edit.php','post-new.php');
}
add_action( 'admin_init', 'remove_admin_menu' );
add_action( 'admin_menu', 'remove_admin_menu' );
And the user can see the contents of the page by entering the menu address in the browser's address bar.
for example :
(domain)/wp-admin/post-new.php
I want the user to see the following message by entering the address in the browser ( for example ) : your Access is Denied
What code should I use?
By WP_Role we can easily update the role by removing or adding new capabilities. Bellow a sample example for user role Administrator.
You can get full understanding to go through official documents.
Here is the link of official documents of WordPress Role and Permission. https://developer.wordpress.org/plugins/users/roles-and-capabilities/