Reputation: 135
I created new user role (Manager)
in WordPress in my functions.php file. This is my code, but it not functional. The Manager only read the posts, can't edit and delete. What's wrong?
Thx.
function ui_new_role() {
//add the new user role
add_role(
'manager',
'Manager',
array(
'edit_' => true,
'read_' => true,
'delete_' => true,
'edit_s' => true,
'edit_others_s' => true,
'publish_s' => true,
'read_private_s' => true,
'delete_s' => true,
'delete_private_s' => true,
'delete_published_s' => true,
'delete_others_s' => true,
'edit_private_s' => true,
'edit_published_s' => true,
)
);
}
add_action('admin_init', 'ui_new_role');
Upvotes: 2
Views: 1097
Reputation: 9373
Create a new "Manager" role.
$result = add_role(
'manager',
__( 'Manager' ),
array(
'read' => true, // true allows this capability
'edit_posts' => true,
'delete_posts' => true, // Use false to explicitly deny
)
);
if ( null !== $result ) {
echo 'New role created!';
}
else {
echo 'Manager role already exists.';
}
Upvotes: 3
Reputation: 6560
According to the documentation you're adding the role incorrectly. Your privilege names don't match anything I know of. In my opinion it's much better to add via a plugin.
function add_mgr_role()
{
add_role(
'manager',
'Manager',
array(
'read' => true,
'edit_posts' => true,
'delete_posts' => true
)
);
}
register_activation_hook(__FILE__, 'add_mgr_role');
Upvotes: 2