php - Hide certain Advanced Custom Fields from non admins -
i've used acf's "flexible content" create advanced "page builder" authors can create "section" (basically wrapping element css class name , id) , add flexible content (images, wysiwyg etc) it.
what i'd hide fields non admins. don't want old editor able go in , change section's id or class names (as mess layout).
i'm aware of "rules" panel in acf admin can choose display field group 1 type of user role, want same thing individual fields.
it doesn't appear doable admin interface, i'm wondering if knows how done functions.php file? perhaps filter or action can hook , disable fields based on current user's role?
i've attached 2 screenshots showing i'd hidden:
i'd hide these choices "add row" menu:
and i'd these panels invisible non admins:
edit: while we're @ it, wouldn't mind hiding individual fields repeatable too. you'll notice "modifiers" field in first screenshot, nice hide non admins. guess solution pretty same both problems?
i haven't managed hide fields, have managed disable them. unfortunately setting them disabled in acf/load_field
action wasn't enough remove them dropdown menu added css admin page visually hide them @ least. enough seeing editors of site won't best break it.
<?php /** * hide "acf section" related custom fields */ add_action('acf/load_field', 'sleek_hide_acf_section_fields', 10, 1); function sleek_hide_acf_section_fields ($field) { $hide = array('section_name', 'section_modifiers', 'modifiers'); global $current_user; if ((isset($field['_name']) , in_array($field['_name'], $hide)) , (is_admin() && is_user_logged_in() && !in_array('administrator', $current_user->roles))) { $field['disabled'] = true; } return $field; } add_action('admin_head', 'sleek_hide_acf_section_fields_css'); function sleek_hide_acf_section_fields_css () { $hide = array('section_name', 'section_modifiers', 'modifiers'); global $current_user; if (is_admin() && is_user_logged_in() && !in_array('administrator', $current_user->roles)) { echo '<style>'; foreach ($hide $h) { echo 'div.acf-fc-popup a[data-layout="' . $h . '"]{display: none}'; } echo '</style>'; } }
Comments
Post a Comment