Hi @markhewes,
Fields can be disabled by default. Sections are excluded by default when you enable that setting on the main settings page.
I’ll try to provide a hook you can add to your functions.php which disables all html fields later today.
This should help you out:
// Handle HTML Blocks like section fields, and disable them if the setting is true.
add_filter('gfexcel_transformer_fields', function ($fields) {
if (!array_key_exists('html', $fields)) {
$fields['html'] = 'GFExcel\Field\SectionField';
}
return $fields;
});
Be sure you have the sections turned off (this is the default settings).
Hope this helps you out.
Perfect! Thanks so much. Could I also adapt this to exclude other field types? Credit Card, for example?
Yes this should be possible. in that case it would be:
add_filter('gfexcel_transformer_fields', function ($fields) {
if (!array_key_exists('html', $fields)) {
$fields['html'] = 'GFExcel\Field\SectionField';
}
if (!array_key_exists('creditcard', $fields)) {
$fields['creditcard'] = 'GFExcel\Field\SectionField';
}
return $fields;
});
But repeating those lines for even more can be a bit annoying, so something like this would be even better:
// Disable these field types if sections are invisible.
add_filter('gfexcel_transformer_fields', function ($fields) {
// add types to this array
$disable_field_types = [
'html',
'creditcard',
];
foreach ($disable_field_types as $type) {
if (!array_key_exists($type, $fields)) {
$fields[$type] = 'GFExcel\Field\SectionField';
}
}
return $fields;
});
It is possible I’m updating these field types in the future, thats why I added the array_key_exists check. If I provide a specific field class of my own, that will take precedence. But for now I have no such ideas 😉