Hi James
Thank you for your reply. Unfortunately the error is not on the field group editor page. It occurs within the editor view of a page where the fields should (or better: should not) be displayed. Sorry if that was not clear enough before.
I try to describe the situation again (hopefully a bit clearer than before):
The fields with the admin_only option are placed inside a layout field item using a single clone field. This layout field item (among other similar layout field items) are used on pages that use a specific page-template.
That causes multiple undefined index errors (see attachment) and even the message field at the beginning isn’t visible anymore…
sure, but it’s identical to the one on https://www.advancedcustomfields.com/resources/adding-custom-settings-fields/
function acf_admin_only_field_setting( $field ) {
acf_render_field_setting( $field, array(
'label' => __('Admin Only?'),
'instructions' => '',
'name' => 'admin_only',
'type' => 'true_false',
'ui' => 1,
), true);
}
add_action('acf/render_field_settings', 'acf_admin_only_field_setting');
function acf_admin_only_prepare_field( $field ) {
// bail early if no 'admin_only' setting
if( empty($field['admin_only']) ) return $field;
// return false if is not admin (removes field)
if( !current_user_can('administrator') ) return false;
// return
return $field;
}
add_filter('acf/prepare_field', 'acf_admin_only_prepare_field');
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.