Skip to content

Commit ce40d03

Browse files
luizbillsk1sul1
authored andcommitted
Add wplf_allowed_additional_form_fields filter (#132)
Add wplf_allowed_additional_form_fields filter
1 parent 5246984 commit ce40d03

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,25 @@ Disabling additonal fields validation for all forms:
176176
add_filter( 'wplf_disable_validate_additional_fields' , '__return_true' );
177177
```
178178

179+
### Filter: wplf_allowed_additional_form_fields
180+
181+
You can provide your own set of allowed field names, instead of disabling additional field validation entirely.
182+
183+
#### Form specific hooks
184+
185+
This filter supports form specific hooks:
186+
187+
- `wplf_{form_id}_allowed_additional_form_fields`
188+
- `wplf_{form_slug}_allowed_additional_form_fields`
189+
190+
These filters are only applied for the target form by ID or slug.
191+
192+
Disabling additonal fields validation for all forms:
193+
194+
```php
195+
add_filter( 'wplf_allowed_additional_form_fields' , ['dynamic-field-name'] );
196+
```
197+
179198
### Filter: wplf_dynamic_values
180199

181200
Add or customize dynamic values available in forms.

inc/wplf-form-validation.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,14 @@ function wplf_validate_additional_fields( $return ) {
101101
// add all default fields
102102
$default_fields = array( 'referrer', '_referrer_id', '_form_id', 'lang' );
103103

104+
// add all custom fields, form spesific filters
105+
$custom_fields = array();
106+
$custom_fields = apply_filters( "wplf_allowed_additional_form_fields", $custom_fields, $form );
107+
$custom_fields = apply_filters( "wplf_{$form->ID}_allowed_additional_form_fields", $custom_fields, $form );
108+
$custom_fields = apply_filters( "wplf_{$form->post_name}_allowed_additional_form_fields", $custom_fields, $form );
109+
104110
// combine fields
105-
$all_fields = array_merge( $form_fields, $default_fields );
111+
$all_fields = array_merge( $form_fields, $custom_fields, $default_fields );
106112

107113
// make sure fields from all_fields are the only ones present in $_POST
108114
$additional_fields = array();

0 commit comments

Comments
 (0)