Reputation: 126
Using Advanced Custom Fields,
How can i change these defaults ?
Any plugins or snippet example for functions.php ?
Thank you !!
Johan
Upvotes: 3
Views: 3160
Reputation: 847
OK, for force the setting of an ACF field, you should use another hook, named acf/update_field/
. It works like those before :
add_filter('acf/update_field/type=wysiwyg', 'my_custom_acf_filter_wysiwyg', 1);
function my_custom_acf_filter_wysiwyg($field){
$field['media_upload'] = 0;
return $field;
}
And you can use these other for target specific fields :
acf/update_field/name={$field['name']}
acf/update_field/key={$field['key']}
When the settings will be saved, their will be take your custom value.
Upvotes: 1
Reputation: 847
I'am using ACF Pro, so my answer could not works for you...
For your front fields, you can use the acf/format_value
hook, and change the $field
params you want :
Textarea example:
add_filter('acf/format_value/type=textarea', 'my_custom_acf_filter_textarea', 1, 3);
function my_custom_acf_filter_textarea($value, $post_id, $field){
remove_filter('acf/format_value/type=textarea', 'my_custom_acf_filter_textarea', 1);
$field['new_lines'] = '';
$newvalue = acf_format_value($value, $post_id, $field);
return $newvalue;
}
Image example:
add_filter('acf/format_value/type=image', 'my_custom_acf_filter_image', 1, 3);
function my_custom_acf_filter_image($value, $post_id, $field){
remove_filter('acf/format_value/type=image', 'my_custom_acf_filter_image', 1);
$field['return_format'] = 'array';
$newvalue = acf_format_value($value, $post_id, $field);
return $newvalue;
}
Note that you can also force the options for specific fields with this hooks :
acf/format_value/name={$field['_name']}
acf/format_value/key={$field['key']}
And for your backend display, use acf/prepare_field
:
WYSIWYG example:
add_filter('acf/prepare_field/type=wysiwyg', 'my_custom_acf_filter_wysiwyg', 1);
function my_custom_acf_filter_wysiwyg($field){
remove_filter('acf/prepare_field/type=wysiwyg', 'my_custom_acf_filter_wysiwyg', 1);
$field['media_upload'] = 0;
return $field;
}
For the admin display, you can also target specific fields with :
acf/prepare_field/name={$field['name']}
acf/prepare_field/key={$field['key']}
Upvotes: 3