Bit of a long question, but I do believe this situation will occur for other people in other contexts.
Our company needs to create an Employee Assistance Program MU subdirectory network site where our company can create user accounts with a custom user role of client
.
The client
will be another company needing to use our company's EAP services for that company's own employees.
The client
must be able to login to the MU network site admin, and add user accounts with an employee
user role for their employees.
Those employee
accounts will be able to log in to the front end and view restricted EAP content.
For the employee
user role, I have use the code here to create in my theme's functions.php
:
$result1 = add_role( 'employee', __('Employee'),
array(
'edit_users' => false,
'create_users' => false,
'delete_users' => false,
'read' => true,
'edit_posts' => false,
'edit_pages' => false,
'edit_others_posts' => false,
'create_posts' => false,
'manage_categories' => false,
'publish_posts' => false,
'edit_themes' => false,
'install_plugins' => false,
'update_plugin' => false,
'update_core' => false
)
);
Can I get away with only specifying what is true, and not need to specify what is false?
For the client
, I have:
$result2 = add_role( 'client', __('Client Company Admin'),
array(
'edit_users' => true,
'create_users' => true,
'delete_users' => true,
'read' => true,
'edit_posts' => false,
'edit_pages' => false,
'edit_others_posts' => false,
'create_posts' => false,
'manage_categories' => false,
'publish_posts' => false,
'edit_themes' => false,
'install_plugins' => false,
'update_plugin' => false,
'update_core' => false
)
);
I need each client
account to only be able to edit and delete employee
accounts created by that individual client
account, and no other company's employee
accounts.
I gather I could add a hidden custom field to the employee
user role which will be the client
ID (added when the client
creates an employee
), and this custom field must not be editable by the employee
role.
I have searched for how to add a hidden custom field to a custom user role, and haven't been able to find a solution.
So, my questions are:
- How do I add a hidden custom field called
clientID
to a custom user role (employee
)? - How do ensure that when a
client
creates anemployee
, the client's user ID or username (unsure which is best) is added to the newemployee
'sclientID
meta field? - How do I ensure the
client
can only edit or delete anemployee
account (and not other standard user accounts)? - Extending 3, how do I ensure the
client
can only edit and delete anemployee
account where theemployee
account has aclientID
client
's own user ID or username?
Thanks.
list_users
to your client role so they can manage the user list.employee
role register, you have a}
bracket instead of an ending paren)
.