function pf_get_defining_capability_by_role($role_slug) { $caps = pf_get_capabilities(); foreach ($caps as $slug => $cap) { $low_role = pf_get_role_by_capability($slug); # Return the first capability only applicable to that role. if ($role_slug == $low_role) { return $slug; } } }
/** * Get the capability that uniquely matches a specific role. * * If we want to allow users to set access by role, we need to give users the names * of all roles. But Wordpress takes capabilities. This function matches the role with * its first capability, so users can set by Role but WordPress takes capability. * * However, it will check against the system options and either attempt to return * this information based on WordPress defaults or by checking the current system. * * @since 3.x * * @param string $role_slug The slug for the role being checked against. * * @return string The slug for the defining capability of the given role. */ function pf_get_defining_capability_by_role($role_slug) { $pf_use_advanced_user_roles = get_option('pf_use_advanced_user_roles', 'no'); # For those who wish to ignore the super-cool auto-detection for fringe-y sites that # let their user capabilities go wild. if ('no' == $pf_use_advanced_user_roles) { $role_slug = strtolower($role_slug); switch ($role_slug) { case 'administrator': return 'manage_options'; break; case 'editor': return 'edit_others_posts'; break; case 'author': return 'publish_posts'; break; case 'contributor': return 'edit_posts'; break; case 'subscriber': return 'read'; break; } } else { $caps = pf_get_capabilities(); foreach ($caps as $slug => $cap) { $low_role = pf_get_role_by_capability($slug); # Return the first capability only applicable to that role. if ($role_slug == $low_role) { return $slug; } } } }