2017-05-17 244 views
0

我已經在wordpress和admin中創建了一個自定義帖子類型,我可以用這個做任何事情。但是我想創建一個只能添加,編輯和刪除這個自定義文章類型的東西的「客戶端」角色,所以他不可以發佈一個普通文章,編輯它或刪除它,並且與頁面一樣。Wordpress自定義帖子類型角色

這是我的我的自定義後類型的參數

$args = array(
    'labels' => $labels, 
    'public' => true, 
    'has_archive' => true, 
    'publicly_queryable' => true, 
    'query_var' => true, 
    'rewrite' => true, 
    'capability_type' => 'post', 
    'hierarchical' => false, 
    'supports' => array(
     'title', 
     'thumbnail' 
    ), 
    'capabilities' => array(
     'edit_post' => 'edit_portfolio', 
     'edit_posts' => 'edit_portfolios', 
     'edit_others_posts' => 'edit_others_portfolios', 
     'publish_posts' => 'publish_portfolios', 
     'read_post' => 'read_portfolios', 
     'read_private_posts' => 'read_private_portfolios', 
     'delete_post' => 'delete_portfolio', 
    ), 
    'map_meta_cap' => true, 
    'menu_icon' => 'dashicons-screenoptions', 
    'menu_position' => 5, 
    'show_ui' => true, 
    'exclude_from_search' => false 
); 

而這些是我所創建

add_role("client", "Client", array(
    'read' => true, // allows this capability, dashboard 
    'upload_files'=>true, //allows user to upload files 
    'edit_posts' => false, // denies user to edit their own posts 
    'edit_pages' => false, // denies user to edit pages 
    'edit_others_posts' => false, // denies user to edit others posts not just their own 
    'create_posts' => false, // denies user to create new posts 
    'manage_categories' => false, // denies user to manage post categories 
    'publish_posts' => false, // denies the user to publish 
    '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 
    'edit_portfolios' => true, // allows editing of the user’s own portfolio 
    'edit_others_portfolios' => true, // allows the user to edit everyone else’s portfolio 
    'delete_portfolios' => true, // allows to delete portfolio written by that user 
    'delete_others_portfolios' => true, // allows to delete portfolio written by other users 
    'publish_portfolios' => true // allows the user to publish portfolio, otherwise posts stays in draft mode 
)); 
作用

現在的效果是,他們可以看到儀表盤的職位,但不改變或點擊它,不能刪除,當他們發佈消息時,他們最終出現在錯誤屏幕上,他們不應該看到這一點。

在此先感謝

回答

0

我找到了答案,所以對於也有這個問題的人來說。 您必須將此功能置於真實狀態

'delete_posts'=>'delete_portfolios', 
'delete_others_posts'=>'delete_others_portfolios', 
'delete_published_posts'=>'delete_published_portfolios', 
'delete_private_posts'=>'delete_private_portfolios' 
0

我從來沒有使用編程方式完成這一點,但如果你是使用插件不介意的話,我已經使用這個https://wordpress.org/plugins/user-roles-and-capabilities/一個在幾個網站和它的快速和容易。

我知道有些人厭惡插件,但我沒有任何問題。

+0

感謝您的快速回復。 當我看着一個插件,我認爲他們有這樣做的正確權利。 所以我想我需要更多的代碼。 – Arne

相關問題