User capability per post

According to Codex we can perform current_user_can checks for certain post_ID, but I fail to find any bit of info how to set a capability explicitly for that post_ID.

A follow up question – how to set custom capability (for ex. download_doc) of the same type that could be later checked by current_user_can( "download_doc", get_the_ID() );

Related posts

Leave a Reply

1 comment

  1. As far as I know, you can not (easily) set up a custom capability for a certain post/page ID. What is described in the Codex, are the so-called meta capabilities (a set of predefined capabilities with additional arguments/information).

    A (not-that-easy) way is to write your own my_add_cap, my_current_user_can, my_has_cap etc. functions.

    Regarding your follow-up question…
    You could choose to not add/check the capability download_doc with an ID as argument, but the unique ID-based capability download_doc_{$ID} instead.