Using add_filter
will automatically pass $errors
to your callback function:
add_filter('form_errors', 'return_errors');
function return_errors($errors) {
// validate $errors based on form conditions
return $errors;
}
If the filter has more than one variable passed you can access that extra information by adding a filter priority and specifying the number of arguments to pass to the callback function. For example, if the validation function had:
return apply_filters('form_errors', $errors, $posted);
You could use:
add_filter('form_errors', 'return_errors', 10, 2);
function return_errors($errors, $posted) {
// form validation code using $errors or $posted
return $errors;
}
Note the reason you need to set the filter priority explicitly as the third argument in that case is so you can “get to” the fourth argument for add_filter
– which again is the number of filter arguments to pass.