我无法获得它,因此我作为供应商的用户角色可以读取货件的张贴类型。它显示在他们的菜单中,但是当您单击它时,您将无法查看此页面错误消息。
如果我可以,add_cap('read_posts')
但我不希望他们仅查看装运帖子类型,则可以正常查看。
我具有以下功能的供应商用户角色。
WP_Role Object
(
[name] => supplier
[capabilities] => Array
(
[read] => 1
[edit_shipment] => 1
[read_shipment] => 1
[edit_others_shipments] => 1
[publish_shipments] => 1
[read_private_shipments] => 1
[edit_shipments] => 1
[create_shipment] => 1
[read_shipments] => 1
)
)
我已经为运输设置了以下类型
function shipment_post_type() {
$labels = array(
'name' => _x( 'Shipments', 'Post Type General Name', 'sage' ),
'singular_name' => _x( 'Shipment', 'Post Type Singular Name', 'sage' ),
'menu_name' => __( 'Shipments', 'sage' ),
'name_admin_bar' => __( 'Shipments', 'sage' ),
'archives' => __( 'Shipment Archives', 'sage' ),
'parent_item_colon' => __( 'Parent shipment:', 'sage' ),
'all_items' => __( 'All shipments', 'sage' ),
'add_new_item' => __( 'Add New shipment', 'sage' ),
'new_item' => __( 'New shipment', 'sage' ),
'edit_item' => __( 'Edit shipment', 'sage' ),
'update_item' => __( 'Update shipment', 'sage' ),
'view_item' => __( 'View shipment', 'sage' ),
'search_items' => __( 'Search shipments', 'sage' ),
'not_found' => __( 'Not found', 'sage' ),
'not_found_in_trash' => __( 'Not found in Trash', 'sage' ),
'featured_image' => __( 'Featured Image', 'sage' ),
'set_featured_image' => __( 'Set shipment image', 'sage' ),
'remove_featured_image' => __( 'Remove shipment image', 'sage' ),
'use_featured_image' => __( 'Use as shipment image', 'sage' ),
'insert_into_item' => __( 'Insert into shipment', 'sage' ),
'uploaded_to_this_item' => __( 'Uploaded to this shipment', 'sage' ),
'items_list' => __( 'shipments list', 'sage' ),
'items_list_navigation' => __( 'Constests list navigation', 'sage' ),
'filter_items_list' => __( 'Filter shipments list', 'sage' ),
);
$args = array(
'label' => __( 'shipments', 'sage' ),
'description' => __( 'Manage all shipments, sweepstakes and giveaways.', 'sage' ),
'labels' => $labels,
'supports' => array( 'revisions' ),
'taxonomies' => array( '' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-archive',
'show_in_admin_bar' => true,
'show_in_nav_menus' => false,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => true,
'publicly_queryable' => true,
'map_meta_cap' => true,
'capabilities' => array(
'edit_post' => 'edit_shipment',
'read_post' => 'read_shipment',
'read_posts' => 'read_shipments',
'delete_post' => 'delete_shipment',
'delete_posts' => 'delete_shipments',
'edit_posts' => 'edit_shipments',
'edit_others_posts' => 'edit_others_shipments',
'publish_posts' => 'publish_shipments',
'read_private_posts' => 'read_private_shipments',
'create_posts' => 'create_shipments',
),
);
register_post_type( 'shipment', $args );
}
add_action( 'init', 'shipment_post_type', 0 );
检查此解决方案:wordpress.stackexchange.com/a/108375/38771
—
PS
我已经读过很多遍了……按照说明可以做的一切。仍然得到您的权限,直到我授予create_shipments权限。
—
Nicholas Koskowski
您可以在添加角色
—
垫
add_role()
和上限的位置共享您的代码add_cap()
吗?
您是要让供应商在前端还是在后端读取此帖子类型?
—
Myles
这段代码是在插件还是主题中?插件更好,但是无论哪种方式,只要提供有关您的设置的更多信息,我相信我都可以为您提供更全面的解决方案
—
Myles