如何使定制帖子类型对订阅者不可见

时间:2018-04-02 作者:TheKidsWantDjent

我正在尝试使用户角色的自定义帖子类型不可见subscriber. 我该怎么做?

我尝试了以下方法,但似乎不起作用。我的帖子类型为request.

$role = get_role( \'subscriber );

$role->remove_cap( \'read\' );
$role->remove_cap( \'read_request\' );
$role->remove_cap( \'read_private_requests\' );
$role->remove_cap( \'edit_request\' );
$role->remove_cap( \'edit_requests\' );
$role->remove_cap( \'edit_others_requests\' );
$role->remove_cap( \'edit_published_requests\' );
$role->remove_cap( \'publish_requests\' );
$role->remove_cap( \'delete_others_requests\' );
$role->remove_cap( \'delete_private_requests\' );
$role->remove_cap( \'delete_published_requests\' );
我想这可能会满足我的要求,但事实并非如此。有什么想法吗?

这是我自定义帖子类型的一部分:

  register_post_type( \'antrag\', array(

        \'labels\'              => array(
            ...
        ),
        \'public\'              => true,
        \'publicly_queryable\'  => true,
        \'exclude_from_search\' => true,
        \'show_ui\'             => true,
        \'show_in_menu\'        => true,
        \'query_var\'           => true,
        \'rewrite\'             => true,
        \'menu_position\'       => 10,
//          \'capability_type\'     => \'post\',
        \'has_archive\'         => true,
        \'menu_icon\'           => \'dashicons-welcome-write-blog\',
        \'hierarchical\'        => false,
        \'supports\'            => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'comments\', \'excerpt\', \'custom-fields\', \'revisions\' ),
        \'capability_type\'     => array( \'request\', \'requests\' ),
        \'map_meta_cap\'        => true,

    )
);

1 个回复
SO网友:Rajnish Tyagi

register\\u post\\u type()在其参数中接受参数功能。有关可能的值,请参阅get\\u post\\u type\\u capabilities()。

注册自定义帖子类型时,可以在代码中添加这些设置

\'capabilities\' => array(
\'edit_post\'          => \'update_core\',
\'read_post\'          => \'update_core\',
\'delete_post\'        => \'update_core\',
\'edit_posts\'         => \'update_core\',
\'edit_others_posts\'  => \'update_core\',
\'delete_posts\'       => \'update_core\',
\'publish_posts\'      => \'update_core\',
\'read_private_posts\' => \'update_core\'
),

结束

相关推荐