Are you looking for a way to change user role capabilities? This snippet will let you change user role capabilities in order to create your own customized user roles.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin.
IMPORTANT: Capabilities are stored in the database, so if you want to give a capability back to a role after deleting it, you have to use and run the add_cap()
function.
<?php # Get the user role # $edit_contributor = get_role('contributor'); # Contributor can upload media # $edit_contributor->add_cap('upload_files'); # Contributor can no longer delete posts # $edit_contributor->remove_cap('delete_posts'); ?>
For more information about roles and capabilities, check out the WordPress Codex.
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: How to Create a Custom User Registration Form in WordPress.
i tried this not working i need to list user based on the login