不,核心角色和功能不会以您想要的方式限制用户。
您可以尝试一个现成的角色/成员插件。可能有一个可用的选项可以让您限制一个用户的访问。
相反,为页面本身创建自定义帖子类型可能更简单。注册新的帖子类型时,可以使用map_meta_cap
并定义自己的自定义功能。然后,您将创建一个仅具有这些功能的角色,并将该角色分配给该用户,当他们登录时,他们将只能访问其用户配置文件和编辑该特定URL。
例如:
<?php
/* Plugin Name: WPSE Info Page
*/
// Register a new post type called Info (or About, or whatever you choose)
add_action(\'init\', \'wpse_create_cpt\');
function wpse_create_cpt() {
register_post_type(\'info\',
array(
\'label\' => __(\'Info\', \'textdomain\'),
\'public\' => true,
\'show_in_rest\' => true,
\'has_archive\' => false,
\'hierarchical\' => false,
// This is where you define custom capabilities
\'map_meta_cap\' => true,
\'capabilities\' => array(
\'edit_post\' => \'edit_info_page\',
\'read_post\' => \'read_info_page\',
\'delete_post\' => \'delete_info_page\',
\'create_posts\' => \'create_info_pages\',
\'delete_posts\' => \'delete_info_pages\',
\'delete_others_posts\' => \'delete_others_info_pages\',
\'delete_private_posts\' => \'delete_private_info_pages\',
\'delete_published_posts\' => \'delete_published_info_pages\',
\'edit_posts\' => \'edit_info_pages\',
\'edit_others_posts\' => \'edit_others_info_pages\',
\'edit_private_posts\' => \'edit_private_info_pages\',
\'edit_published_posts\' => \'edit_published_info_pages\',
\'publish_posts\' => \'publish_info_pages\',
\'read_private_posts\' => \'read_private_info_pages\'
),
)
);
}
// Create a new role that has full capabilities for the Info post type
add_action(\'init\', \'wpse_create_cpt_role\');
function wpse_create_cpt_role() {
add_role(\'info\', \'Info Editor\');
// You probably want them to be able to read on the front end
$info->add_cap(\'read\');
// And upload files, but that\'s up to you
$info->add_cap(\'upload_files\');
// Here\'s where you really decide - should they be able to add, edit, delete
// or maybe only edit (theirs, others, private, and published)
// and not delete the page, or add additional pages
$info->add_cap(\'create_info_pages\');
$info->add_cap(\'delete_info_pages\');
$info->add_cap(\'delete_others_info_pages\');
$info->add_cap(\'delete_private_info_pages\');
$info->add_cap(\'delete_published_info_pages\');
$info->add_cap(\'edit_info_pages\');
$info->add_cap(\'edit_others_info_pages\');
$info->add_cap(\'edit_private_info_pages\');
$info->add_cap(\'edit_published_info_pages\');
$info->add_cap(\'publish_info_pages\');
$info->add_cap(\'read_private_info_pages\');
}
// Optional - give Admin users the ability to edit the info page
// (Since you\'re using custom capabilities, they can\'t edit unless you do this)
add_action(\'init\', \'wpse_grant_cpt_caps\');
function wpse_grant_cpt_caps() {
$admin = get_role(\'administrator\');
// Again, decide which capabilities you want them to have
// (usually you\'ll want to grant full capabilities to Admins)
$admin->add_cap(\'create_info_pages\');
$admin->add_cap(\'delete_info_pages\');
$admin->add_cap(\'delete_others_info_pages\');
$admin->add_cap(\'delete_private_info_pages\');
$admin->add_cap(\'delete_published_info_pages\');
$admin->add_cap(\'edit_info_pages\');
$admin->add_cap(\'edit_others_info_pages\');
$admin->add_cap(\'edit_private_info_pages\');
$admin->add_cap(\'edit_published_info_pages\');
$admin->add_cap(\'publish_info_pages\');
$admin->add_cap(\'read_private_info_pages\');
}
?>
您可以将其作为插件安装以创建CPT和角色,然后您仍然需要创建(或更新)一个用户,为该用户提供新CPT的新角色。如果您以前将该页面发布为另一个帖子类型(例如,一个页面),您将希望复制该信息,将该页面发布为CPT,并删除原始页面。