对于客户端角色,请使用此;
// 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
)
);
然后使用上面的代码重定向登录,如果并且仅当它是客户端角色。
一个页面模板客户端页面放置此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");
}
显然,我们需要让管理员看到页面;
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");
}
}