I’ve used ACF’s “Flexible Content” to create a fairly advanced “page builder” where authors can create a “section” (basically just a wrapping element with a CSS class name and ID) and then add all my flexible content (images, wysiwyg etc) to it.
What I’d like to do is hide some fields for non admins. I don’t want any old editor to be able to go in and change a section’s ID or class names (as it would mess up the layout).
I’m aware of the “Rules” panel in the ACF admin where you can choose to only display a certain field group to one type of user role, but what I want is that same thing but for individual fields.
It doesn’t appear to be doable from the admin interface, but I’m wondering if someone knows how it could be done from my functions.php file? Perhaps some filter or action I can hook into and disable certain fields based on the current user’s role?
I’ve attached two screenshots showing what I’d like hidden:
I’d like to hide these choices from the “Add row” menu:
And I’d like these panels to be invisible to non admins:
Edit: While we’re at it, I wouldn’t mind hiding individual fields from a repeatable too. You’ll notice a “Modifiers” field in the first screenshot, that too would be nice to hide from non admins. I guess the solution would be pretty much the same for both problems?
As of ACF 5.0.0 there is an easier way to do this without having to disable the field or output CSS. If you use the
acf/prepare_field
hook and returnfalse
the field will not render.The documentation for that filter can be found here: https://www.advancedcustomfields.com/resources/acf-prepare_field/
I haven’t managed to actually hide the fields, but I have managed to disable them. Unfortunately simply setting them to disabled in the
acf/load_field
action wasn’t enough to remove them from the dropdown menu so I also added some CSS to the admin page to visually hide them at least. This is good enough seeing as the editors of the site won’t exactly do their best to break it.