Home › Forums › Feature Requests › New Conditional Logic Option: User Role
Would be really handy for some of the more complicated layouts to be able to (sort of) lock fields by not displaying them unless a user is an admin. The logic is there for entire field groups but it would be really handy to have it on field sets.
My two use cases today:
Actually, now that I think about it, it could be handy to have a lot of the global fieldset rules on a per field basis. Let’s say I use a gallery field in a few fieldsets and those fieldsets are assigned to different pages/page templates/whatevs. In some instances, the galleries need an extra field to display an HTML header/title. Instead of making two separate fieldsets, I could make one, show it on both pages but only show the HTML title field on specific pages.
Perhaps this stuff could be written as (and better suited for) a plugin, I’m not sure.
Thanks for reading!
I am 100% on board with this.
I’ve got clients who need to let their users do things like submit and edit a post. They don’t want that user to be able to feature the post on the front page though, which means rolling my own meta box in functions.php. Not that it’s hard to roll your own metabox with a “manage_options” conditional in a system like WP Alchemy – but boy, it’d sure be convenient if ACF did it natively.
+1 Super reasonable. I am wanting this today (which is why I found this). Has anyone worked a reasonably generic hack for this?
@jjrohrer I wound up doing something like this:
https://gist.github.com/jancbeck/3178689
to add each user’s role as a classname on the body. Then used an admin style sheet to hide the field.
As I think of this, I would really like a hook that asked if a field would display and if it could be saved. That would make it easy for us to a capability check in there, but also to add some other logic.
@will If I understand your gist, it just hides the option, leaving it open to security issues. I think I saw and ‘update’ hook and ‘validation’ hook. Maybe I could force the data always revert to saved state. Sounds super fragile.
For anyone that’s looking for something like this, I have created a little add on that adds a user role setting to every field. It’s kind of a big hammer approach to making making fields only available to specific user roles and it only works with ACF5 (Pro). https://github.com/Hube2/acf-user-role-field-setting. If you only want to do this for some fields rather than all fields it would be easy to use the code ans an example of what needs to be done.
Why isn’t this a feature of ACF?
ps. The plugin works, thanks!
I would also like to see this as a native ACF feature, both:
– fields hidden for certain (low) user levels
– fields read only for certain (low) user levels
+1, as Andrija puts it:
– fields hidden for certain user roles
– fields read only for certain user roles
The topic ‘New Conditional Logic Option: User Role’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.