[wp-hackers] Plugin Port to 2.0: Showing private posts in single-view

Ryan Boren ryan at boren.nu
Wed Dec 21 22:55:16 GMT 2005

On Wed, 2005-12-21 at 11:48 -0800, Filipe Fortes wrote:
> Thanks for your help Ryan!
> > Other plugins might loop over the posts in the query and call
> > current_user_can() for each, so you should take that into account.
> What's the best way to know what the current post is during the callback?

current_user_can('read_post', $post->ID)

When current_user_can() is called with a post id as the second arg,
you'll be able to get that id by digging into the cap data that is
passed as the third argument to your hook.

Here's an example taken from the post sharing plugin I linked to.

function ps_user_has_cap($user_caps, $requested_caps, $cap_data) {
$post_id = $cap_data[2];

> > If there are any extra hooks you need added, let us know now and we can
> > try to get them into 2.0.
> The biggest thing that's been missing is that the posts_where and
> posts_join filters aren't called when constructing archives (date or
> category), meaning the archives can't take into account the private
> posts (since post_status = 'publish' is hard coded).

I thought we always called those filters.  Maybe I'm not following.  Can
you elaborate a bit more?

If you mean that current_user_can() isn't always called, that's true.
You might need to loop over the_posts and call current_user_can() for
each.  I thought about putting such a loop in get_posts() and calling
current_user_can('read_post', $post_id) for each so that plugins can hop
onto the read_post cap, but decided I would just leave all of that up to
plugins since they'll probably want to check against their own custom
cap anyway.


More information about the wp-hackers mailing list