Details
if (
! isset( $post_type_object->cap->edit_post ) ||
! current_user_can( $post_type_object->cap->edit_post, $post_id )
) {
throw new UserError( /* authorization error */ );
}
Status transitions should also enforce the relevant post type capabilities. In particular, changing a post to a public/future status should require the post type's publish_posts capability. Tests should cover at least:
- Contributor updating their own draft: allowed.
- Contributor publishing their own draft: denied or changed to
pending. - Contributor editing their own previously published post: denied.
- Author publishing and editing their own post: allowed.
- Contributor editing another author's post: denied.