Skip to content

Instantly share code, notes, and snippets.

@Lizdo
Created February 22, 2010 05:11
Show Gist options
  • Save Lizdo/310818 to your computer and use it in GitHub Desktop.
Save Lizdo/310818 to your computer and use it in GitHub Desktop.
<?php
function elbe_current_user_can($capability, $current_user) {
//replace wp2_ with your database prefix -.-
$roles = get_option('wp2_user_roles');
$user_roles = $current_user->wp_capabilities;
if ($user_roles == null)
return false;
$user_roles = array_keys($user_roles, true);
$role = $user_roles[0];
$capabilities = $roles[$role]['capabilities'];
if ( in_array( $capability, array_keys( $capabilities, true) ) ) {
return true;
}
}
//...
//in theme logic somewhere
if (elbe_current_user_can('discount',$current_user))
//do something
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment