Change Role Capabilities

There are several roles you can give your users in WordPress, like Contributor, Author or Administrator. These are pre-defined and has certain capabilities. To change these capabilities and create your own, customized user roles, just add the following to functions.php:

The different roles and capabilities are listed in the WordPress Documentation.

IMPORTANT! The capabilities are written to the database, so if you want to give back a capability to a role, you have to use the add_cap-function.

Code Snippet:

<?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');
?>

Posted in Admin area