将新用户添加到您的WordPress站点以仅编辑一个页面

时间:2019-12-02 作者:Soheil Paper

我们是university business incubator 作为一家公司和一所大学的网站,我想知道是否有任何模块可以创建仅用于编辑一页(公司简介页)的受限帐户。

更新时间:

我看到了here , 而且是Author 帐户只能用于编辑其页面?

感谢您的关注。

1 个回复
SO网友:WebElaine

不,核心角色和功能不会以您想要的方式限制用户。

您可以尝试一个现成的角色/成员插件。可能有一个可用的选项可以让您限制一个用户的访问。

相反,为页面本身创建自定义帖子类型可能更简单。注册新的帖子类型时,可以使用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,并删除原始页面。

相关推荐

WP_LIST_PAGES获取当前页面的空洞层次结构

例如,具有以下页面层次结构Page1 - SubPage1_1 - SubPage1_2 -- SubSubPage1_2_1 Page2 - SubPage2_1 - SubPage2_2 -- SubSubPage2_2_1 例如,请求SubSubPage1_2_1 我怎样才能适应wp_list_pages 孔层次结构?预期结果Page1 - SubPage1_1 - SubPa