[wp-hackers] Passing arguments to current_user_can() function
Dion Hulse (dd32)
wordpress at dd32.id.au
Fri May 27 13:25:41 UTC 2011
You need to check against the Custom Post Types permission, which may or may
not, have the same format as the edit posts caps.
Off the top of my head (You''ll have to check the object
references/functions)
$post_obj = get_post_type_object( $post->post_type );
if ( current_user_can( $post_obj->caps->edit_post ) ) { .... }
if you dump out the object and look at the caps array, you should be able to
figure it out
On 27 May 2011 23:10, prasath nadarajah <n.prasath.002 at gmail.com> wrote:
> Hi hackers
> This may sound like a php question
>
> I,m developing a plugin for extending web services for WordPress.
> I came across a problem in passing arguments to the current_user_can
> function.
>
> Just a passing a single or double quoted string works fine
> like current_user_can('edit_posts') or
> current_user_can("edit_posts").
>
> But when i want to pass an argument which depends on a variable it gives
> different results
> If i want to check a capability against a given custom_post_type i could'nt
> figure out a way to do that.
>
> $post_type['name'] // this variable holds the name of the post_type. in
> this case 'post'
>
> current_user_can( "edit_{$post_type['name'] }s" ) // this returns
> false for an admin
> current_user_can( "edit_".$post_type['name']."s" ) // this returns
> false for an admin
>
> current_user_can( "edit_posts" ) // this
> returns true for an admin
>
> But "edit_{$post_type['name'] }s" === "edit_posts" // this evaluates
> true.
>
> Is there anyway to construct the capability string based on the
> post_type_name
> which can be passed to the current_user_can() function.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list