Wordpress 职位类型的克隆角色功能
我在我的插件中注册了一个自定义帖子类型(“播放列表”)。 我读过很多关于角色和能力的书,但这很难完全理解。。。 我希望实现的是按角色克隆帖子类型的功能: 在我的例子中,我希望从“post”(按角色)获得功能,并将它们分配给我的自定义post类型(“播放列表”) 我不想像下面那样使用“功能类型”,因为我不想将“发布”功能分配给我的“播放列表”发布类型,我希望它有自己的功能,但每个角色都有相同的默认值Wordpress 职位类型的克隆角色功能,wordpress,custom-post-type,role,capability,Wordpress,Custom Post Type,Role,Capability,我在我的插件中注册了一个自定义帖子类型(“播放列表”)。 我读过很多关于角色和能力的书,但这很难完全理解。。。 我希望实现的是按角色克隆帖子类型的功能: 在我的例子中,我希望从“post”(按角色)获得功能,并将它们分配给我的自定义post类型(“播放列表”) 我不想像下面那样使用“功能类型”,因为我不想将“发布”功能分配给我的“播放列表”发布类型,我希望它有自己的功能,但每个角色都有相同的默认值 function register_post_type() { $args = array
function register_post_type() {
$args = array(
...
'capability_type' => 'post', //I think I don't need this
...
);
register_post_type( 'playlist', $args );
)
所以我想我需要更像这样的东西:
function register_post_type() {
$args = array(
...
'capability_type' => 'playlist',
'map_meta_cap' => true,
'capabilities' => array(
'edit_post' => 'edit_playlist',
'read_post' => 'read_playlist',
'delete_post' => 'delete_playlist',
'create_posts' => 'create_playlists',
'edit_posts' => 'edit_playlists',
'edit_others_posts' => 'manage_playlists',
'publish_posts' => 'manage_playlists',
'read_private_posts' => 'read',
'read' => 'read',
'delete_posts' => 'manage_playlists',
'delete_private_posts' => 'manage_playlists',
'delete_published_posts' => 'manage_playlists',
'delete_others_posts' => 'manage_playlists',
'edit_private_posts' => 'edit_playlists',
'edit_published_posts' => 'edit_playlists'
),
...
);
register_post_type( 'playlist', $args );
)
但在此之后,我需要运行一个函数,根据“post”功能将这些功能分配给每个角色。
明白我的意思吗
你知道我怎样才能做到这一点吗
谢谢
附:有用链接:这是我最后做的。
这并不完全是问题的答案(克隆角色),但它满足了我的需要
function register_post_type() {
...
'capability_type' => 'playlist',
'map_meta_cap' => true,
'capabilities' => array(
// meta caps (don't assign these to roles)
'edit_post' => 'edit_playlist',
'read_post' => 'read_playlist',
'delete_post' => 'delete_playlist',
// primitive/meta caps
'create_posts' => 'create_playlists',
// primitive caps used outside of map_meta_cap()
'edit_posts' => 'edit_playlists',
'edit_others_posts' => 'manage_playlists',
'publish_posts' => 'manage_playlists',
'read_private_posts' => 'read',
// primitive caps used inside of map_meta_cap()
'read' => 'read',
'delete_posts' => 'manage_playlists',
'delete_private_posts' => 'manage_playlists',
'delete_published_posts' => 'manage_playlists',
'delete_others_posts' => 'manage_playlists',
'edit_private_posts' => 'edit_playlists',
'edit_published_posts' => 'edit_playlists'
),
...
);
register_post_type( $this->post_type, $args );
}
function set_roles_capabilities(){
global $wp_roles;
if ( ! isset( $wp_roles ) ) $wp_roles = new WP_Roles();
//create a new role, based on the subscriber role
$role_name = 'playlist_author';
$subscriber = $wp_roles->get_role('subscriber');
$wp_roles->add_role($role_name,__('Playlist Author','xspfpl'), $subscriber->capabilities);
//list of custom capabilities and which role should get it
$wiki_caps=array(
'manage_playlists'=>array('administrator','editor'),
'edit_playlists'=>array('administrator','editor',$role_name),
'create_playlists'=>array('administrator','editor',$role_name),
);
foreach ($wiki_caps as $wiki_cap=>$roles){
foreach ($roles as $role){
$wp_roles->add_cap( $role, $wiki_cap );
}
}
}
register_activation_hook( __FILE__ , 'set_roles_capabilities' );//roles & capabilities
add_action( 'init', 'register_post_type');