/** * Check whether a role has a capability or not. * * @access public * @since 0.7.5 * @param (string) $role The role name. * @param (string) $cap The capability. * @return (bool) */ public static function hasCapability($role, $cap) { // Bring a copy of this into scope. $instance = self::getInstance(); if (!isset($instance->roles[$role])) { return FALSE; } $wp_role = new WP_Role($role, $instance->roles[$role]['capabilities']); return $wp_role->has_cap($cap); }
public function hasCapability($role, $cap) { global $wp_roles; /* * Check to make sure $wp_roles has been initialized and set. * If it hasn't it is initialized. This was done because this method * can be called before the $wp_roles has been initialized. */ if (!isset($wp_roles)) { $wp_roles = new WP_Roles(); } $wpRoleDataArray = $wp_roles->roles; $wpRoleCaps = $wpRoleDataArray[$role]['capabilities']; $wpRole = new WP_Role($role, $wpRoleCaps); return $wpRole->has_cap($cap); }