我已经创建了一个自定义帖子类型“Extension”和一个角色“Extension Author”。此角色的用户只能编辑自己的扩展名。
现在,用户可以单击顶部栏中的“编辑扩展”,然后进入编辑模式。
如何防止扩展作者进入非他/她自己的扩展的编辑视图?我在设置功能时是否遗漏了什么?
创建自定义帖子类型:
$labels = array(
\'name\' => _x( \'Extensions\', \'Post Type General Name\', \'text_domain\' ),
\'singular_name\' => _x( \'Extension\', \'Post Type Singular Name\', \'text_domain\' ),
\'menu_name\' => __( \'Extensions\', \'text_domain\' ),
\'parent_item_colon\' => __( \'Parent Extension:\', \'text_domain\' ),
\'all_items\' => __( \'All Extensions\', \'text_domain\' ),
\'view_item\' => __( \'View Extension\', \'text_domain\' ),
\'add_new_item\' => __( \'Add New Extension\', \'text_domain\' ),
\'add_new\' => __( \'Add New\', \'text_domain\' ),
\'edit_item\' => __( \'Edit Extension\', \'text_domain\' ),
\'update_item\' => __( \'Update Extension\', \'text_domain\' ),
\'search_items\' => __( \'Search Extension\', \'text_domain\' ),
\'not_found\' => __( \'No Extensions found\', \'text_domain\' ),
\'not_found_in_trash\' => __( \'No Extensions found in Trash\', \'text_domain\' ),
);
$rewrite = array(
\'slug\' => \'extension\',
\'with_front\' => true,
\'pages\' => true,
\'feeds\' => true,
);
$capabilities = array(
\'edit_post\' => \'edit_extension\',
\'read_post\' => \'read_extension\',
\'delete_post\' => \'delete_extension\',
\'edit_posts\' => \'edit_extensions\',
\'edit_others_posts\' => \'edit_others_extensions\',
\'publish_posts\' => \'publish_extensions\',
\'read_private_posts\' => \'read_private_extensions\',
);
$args = array(
\'labels\' => $labels,
\'supports\' => array( \'title\',),
\'hierarchical\' => false,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'menu_position\' => 5,
\'menu_icon\' => \'dashicons-admin-generic\',
\'can_export\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'rewrite\' => $rewrite,
\'capability_type\' => \'extension\',
\'capabilities\' => $capabilities,
);
register_post_type( \'extension\', $args );
正在创建用户角色:
$extension_author_role = add_role(\'extension_author\', \'Extension Author\', array(
\'read\' => true,
\'upload_files\' => true,
\'edit_extension\' => true,
\'read_extension\' => true,
\'delete_extension\' => true,
\'edit_extensions\' => true,
\'edit_others_extensions\' => false,
\'publish_extensions\' => true,
\'read_private_extensions\' => false,
)
);