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!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc
— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 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.