Skip to content

Commit deab1e3

Browse files
committed
Required fields that are conditionally shown/hidden shouldn't required data unless shown
@polevaultweb This is related to WPUserManager/wpum-custom-fields#71 I need to add filter in validate_fields function to allow skip field validation.
1 parent 10bfbe0 commit deab1e3

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

includes/abstracts/abstract-wpum-form.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ protected function str_len( $str ) {
298298
protected function validate_fields( $values ) {
299299
foreach ( $this->fields as $group_key => $group_fields ) {
300300
foreach ( $group_fields as $key => $field ) {
301+
// Skip validation if field conditional logic not met.
302+
if ( apply_filters( 'wpum_form_skip_field_validation', false, $key, $values[ $group_key ], $group_fields ) ) {
303+
continue;
304+
}
301305
if ( $field['required'] && empty( $values[ $group_key ][ $key ] ) ) {
302306
return new WP_Error( 'validation-error', sprintf( __( '%s is a required field', 'wp-user-manager' ), $field['label'] ) );
303307
}

0 commit comments

Comments
 (0)