Home › Forums › Bug Reports › Field saving does not respect unfiltered_html capability › Reply To: Field saving does not respect unfiltered_html capability
OK. I’m fine with normal content areas being filtered. Although, the nature of the filter seems kinda odd to me though, because if the super admin adds code to a post, then a non-super-admin comes along and updates the same post, the stuff the super-admin added will disappear.
Anyway, this is the filter I made. It depends on the code field ending with ‘code’ in its name.
// remove the html filter on all ACF fields
add_filter('acf/allow_unfiltered_html', 'wilirius_acf_allow_unfiltered_html_all_fields');
function wilirius_acf_allow_unfiltered_html_all_fields() {
return true;
}
// re-apply filter to non-code fields
add_filter('acf/update_value', 'wilirius_acf_disallow_unfiltered_html_non_code_field', 1, 3);
function wilirius_acf_disallow_unfiltered_html_non_code_field($value, $post_id, $field){
if(substr($field['name'], -4) !== 'code') {
if(
$field['type'] !== 'tab' &&
$field['type'] !== 'group' &&
$field['type'] !== 'repeater' &&
$field['type'] !== 'flexible_content' &&
$field['type'] !== 'clone'
){
$value = wp_kses_post($value);
}
}
return $value;
}
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’re working hard on Advanced Custom Fields PRO 6.0, and Beta 1 is now available 🚀
— Advanced Custom Fields (@wp_acf) August 12, 2022
Featuring improved performance for Repeater fields with large datasets, and a new generation of ACF Blocks.
Let’s take a look 🧵https://t.co/Befre3kFAo
© 2022 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.