Home › Forums › Backend Issues (wp-admin) › Admin only custom field setting outputs empty input fields › Reply To: Admin only custom field setting outputs empty input fields
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.