I’m trying to get a list of roles and filter them by a specific capability (custom). I’ve ran across this post, but I’d like to filter the roles by whether they’re capable to, say, edit_post
.
-Zack
I’m trying to get a list of roles and filter them by a specific capability (custom). I’ve ran across this post, but I’d like to filter the roles by whether they’re capable to, say, edit_post
.
-Zack
You must be logged in to post a comment.
Untested, but should be easily extendable(or something you can take ideas from).
Example usage:
If the function returned false you’d know the role(s) does not have the cap, ie..
Else, the result is an array of roles that do have the cap(whether you passed in a single role or several).
You could trim it down and just have a return value if that’s preferred, but you mentioned wanting a list of roles that have a cap, so i naturally assumed an array would be a logical choice..
Converting an array to a string is fairly easy, and you can even use your own seperator, simply call
implode()
, like so…(using the example variable from earlier)..You could also move the implode into the function to avoid having to do implodes when calling the function, and do note, implode will work correctly on a single item array to(ie. you’ll get a string with no seperator).
I hope that’s helpful in anycase… 🙂
EDIT:
Function will now look at all the roles if the first arg($roles) is set to false.