Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Validate WYSIWYG character limit
* Validate WYSIWYG field so that it outputs only 250 characters
* Targets the overview field in the documentation only.
* @param bool $valid Check the validity of the field.
* @param string $value The field value.
* @param array $field Array with the field details.
* @param string $input Input string definition: acf[field_xxxxxxxxxxxxx].
* @return bool|string True if valid, fail if invalid.
public function validate_wysiwyg_field_length( bool $valid, string $value, array $field, string $input ) {
if ( ! $valid ) {
return $valid;
if ( strlen( wp_strip_all_tags( $value ) ) > 250 ) {
$valid = esc_html__( 'Maximum limit for the input is 250 characters.', 'developer-portal' );
return $valid;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.