[wp-hackers] Passing arguments to current_user_can() function

prasath nadarajah n.prasath.002 at gmail.com
Fri May 27 13:10:12 UTC 2011


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.


More information about the wp-hackers mailing list