最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to only display all posts to a custom User Role?

programmeradmin0浏览0评论

I have a custom user role and I want to display all custom website posts to them, without letting them edit/delete them. Right now the custom post doesn't show up in their dashboard. I know it will show up when I add the edit and delete caps, but I only want them to be able to see their "websites". Ultimately they only get to see the websites that have a custom field that is a relation to the client user. So client1 can only see websites of client1, etc. I have the following code:

// Add the Client user role
function add_client_user_role() {

  $capabilities = array(
        'read'                           => true,
    'read_website'           => true
  );

  add_role( 'client', 'Client' );

    $client = get_role( 'client' );
    $client->add_cap( 'read' );
    $client->add_cap( 'read_website' );

}

add_action( 'init', 'add_client_user_role', 10 );

How can I achieve this?

EDIT: Ok, I found the hook restrict_manage_posts which I can use to show only the posts assigned to them. Now I still need a way to make sure they show up, without letting them edit the posts. So the custom Post should show up in the dashboard without me giving them caps to edit.

发布评论

评论列表(0)

  1. 暂无评论