For the client role, use this;
// Add a client user role
$result = add_role( 'client', __(
'Client' ),
array(
'read' => true, // true allows this capability
'edit_posts' => false, // Allows user to edit their own posts
'edit_pages' => false, // Allows user to edit pages
'edit_others_posts' => false, // Allows user to edit others posts not just their own
'create_posts' => false, // Allows user to create new posts
'manage_categories' => false, // Allows user to manage post categories
'publish_posts' => false, // Allows the user to publish, otherwise posts stays in draft mode
'edit_themes' => false, // false denies this capability. User can’t edit your theme
'install_plugins' => false, // User cant add new plugins
'update_plugin' => false, // User can’t update any plugins
'update_core' => false // user cant perform core updates
)
);
and then use the code above to redirect the login if, and only if, it’s a client role.
One the page template Client Page put this before get_header()
:
$current_user = wp_get_current_user();
$client = $current_user->user_login;
$slug = get_post_field( 'post_name', get_post() );
$client = strtolower($client);
if ($client != $slug) {
header("Location: /index.php");
}
and, obviously, we need to let admins see the page;
if (!current_user_can('administrator')) {
$current_user = wp_get_current_user();
$client = $current_user->user_login;
$slug = get_post_field( 'post_name', get_post() );
$client = strtolower($client);
if ($client != $slug) {
header("Location: /index.php");
}
}