Support

Account

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');