Home › Forums › ACF PRO › Add/extend custom field settings › Reply To: Add/extend custom field settings
I see there is no way of customizing existing fields settings, so I made up my own solution which is based on the instructions
content. Here is the code (in case anyone is interested), what it does is limiting a maximum number of words in WYSIWYG field:
// Check if number of words in WYSIWYG is less than max number
// provided inside field instructions. Supported instructions format is (see the regex):
// Max. 300 words
// max 300 words
// max.300 words
add_filter('acf/validate_value/type=wysiwyg', function ( $valid, $value, $field, $input ){
if( !$valid ) {
return $valid;
}
$matches = [];
preg_match('/max[^\d]*(\d+) word/i', $field['instructions'], $matches);
if ( empty( $matches ) || empty( $matches[1] ) ) {
return $valid;
}
$max_words = (int) $matches[1];
// check words number
$words_number = str_word_count( strip_tags( $value ) );
if ( $words_number > $max_words ) {
$valid = "Text is too long ( ${words_number} words ). Max number of words is ${max_words}.";
}
// return
return $valid;
}, 10, 4);
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 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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.