How to assign or remove user permissions in WordPress

In wordpress, it is very easy to add and remove permissions to your wordpress registered users. For example, you can set wordpress default user role to “contributor” which means those who register in your website, automatically become contributors and they will be able to post articles in your wordpress “pending review”. In that way you restrict your users not to spam you by publishing posts. If you set the user role to “author”, then they will instantly publish posts.

Permissions, are otherwise called “capabilities” in wordpress, depending on user role. For example “subscribers” can only read in your website and cannot submit posts. Similarly “contributors” cannot delete/edit posts once published by admin.

The best plugin i have seen to customize user panel permission is adminimize. Be sure to play around with this plugin.

Be sure to read this: http://codex.wordpress.org/Roles_and_Capabilities

The good news is you alter the user permissions, which wordpress assigns by default. You may allow contributors permission to delete and edit posts even after they are published. It is so easy and can be done with just 2 lines of code.

Go to your theme folders function.php,  and place the below code and this will alter permission to all your users in the admin area. You could even use this code in your plugin.

This code runs, when admin_init hook is called during load of admin section.

[php]
function change_user_permissions() {

$role = get_role( ‘contributor’ ); // gets the author role

$role->add_cap( ‘edit_others_posts’ ); //edit others’ posts for current theme only
$role->add_cap( ‘edit_posts’ ); // edit own posts
$role->add_cap(‘delete_posts’); // delete own posts
$role->add_cap(‘publish_posts’); // publish own posts

$role->remove_cap(‘edit_posts’); //removes the permission set before
$role->remove_cap(‘delete_posts’); // delete own posts
}

add_action( ‘admin_init’, ‘change_user_permissions’);
 [/php]

For complete list of user capability functions, see: http://codex.wordpress.org/Roles_and_Capabilities