Remove publishing capability from user IDs
I'm trying to remove the capability of users other than the administrator/superadmin (ID number 1) to add a page, I know that there are plugins which you can edit the wordpress role but in my case I need it to be per user/username/userid (no plugin that I no of is available)..
Currently user number 2 needs to be 'Administrator' because a specific plugin I use only displays reports to 'Administrator' role but I need to remove add page capabilities. I have the following code:
function modify_capabilities()
{
global $userdata;
get_currentuserinfo();
$userdata->ID != 1 ->remove_cap('publish_pages');
}
add_action('admin_init','modify_capabilities');
But it doesn't work.. The error is in this line开发者_如何学Python:
$userdata->ID != 1 ->remove_cap('publish_pages');
Your code seems off by a bit:
function modify_capabilities()
{
global $userdata;
get_currentuserinfo();
if ($userdata->ID != 1) {
$role = get_role('author');
$role->remove_cap('publish_pages');
$role->remove_cap('publish_posts');
}
}
add_action('admin_init','modify_capabilities');
Updated based on your comments and taking the original details from the blog you linked to. Not sure why you removed those parts though...
精彩评论