validate_callback function for custom typography field
Hi, I have customized the typography field. Now instead of select the same CSS unit for the fields 'font-size', 'line-height', 'word-spacing an 'letter-spacing the user can enter the number and the unit directly in the text field (for example the user can enter 1em for font-size and 1px for letter-spacing). To validate the field I have a function like this to check the value in the text input:
if (!function_exists('validate_typography')):
function validate_typography($field, $value, $existing_value) {
$error = false;
$fields_to_check = array('font-size', 'line-height', 'word-spacing', 'letter-spacing');
foreach ($value as $the_key => $the_value) {
foreach ($fields_to_check as $fields_to_check_value) {
if ($the_key == $fields_to_check_value) {
$regex = '<my regex>';
if (!preg_match($regex , $the_value)) {
$error = true;
$field['msg'] = 'Error';
}
}
}
}
$return['value'] = $value;
if ($error == true) {
$return['error'] = $field;
}
return $return;
}
}
The function check correctly if there is an error or if the error has been corrected but if the error has been corrected the custom error message that appears under the field remains visible. How can I modify the function to make it work properly? Thanks.
If you customized the core, you're on your own, unless you want to pay for premium support. We do not support custom modifications.