1

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() );

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.

  • 1
    Thanks, that's how I do it currently. Didn't know about the meta caps and implementing something like these is probably overkill. – Z. Zlatev Apr 15 '13 at 11:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.