custom post types – Understanding capabilities parameter in register_post_type()


So far what I’ve understood:

Capabilities parameter allows the plugin to set edit, read and delete capabilities for a certain post_type applicable to the all user roles. The primitive capabilities are a derivative of these. For the eight other primitive caps reference through map_meta_cap, should the coder manually set each of these for each set of roles or are by default set according to the meta caps?

Also why the need to specify the capability_type for use in?:

[cap] => stdClass Object
    // Meta capabilities

    [edit_post]      => "edit_{$capability_type}"
    [read_post]      => "read_{$capability_type}"
    [delete_post]        => "delete_{$capability_type}"

    // Primitive capabilities used outside of map_meta_cap():

    [edit_posts]         => "edit_{$capability_type}s"
    [edit_others_posts]  => "edit_others_{$capability_type}s"
    [publish_posts]      => "publish_{$capability_type}s"
    [read_private_posts]     => "read_private_{$capability_type}s"

    // Primitive capabilities used within map_meta_cap():

    [read]                   => "read",
    [delete_posts]           => "delete_{$capability_type}s"
    [delete_private_posts]   => "delete_private_{$capability_type}s"
    [delete_published_posts] => "delete_published_{$capability_type}s"
    [delete_others_posts]    => "delete_others_{$capability_type}s"
    [edit_private_posts]     => "edit_private_{$capability_type}s"
    [edit_published_posts]   => "edit_published_{$capability_type}s"
    [create_posts]           => "edit_{$capability_type}s"

Why not just use the capability_type in index and set boolean values for each? like:

[edit_{$capability_type}] => bool

brittle_spirit 1 year 2022-12-23T09:44:42-05:00 0 Answers 0 views 0

Leave an answer