Plugin Updates
This commit is contained in:
@@ -153,6 +153,75 @@ function wpcf7_swv_add_select_rules( $schema, $contact_form ) {
|
||||
}
|
||||
|
||||
|
||||
add_action(
|
||||
'wpcf7_swv_create_schema',
|
||||
'wpcf7_swv_add_select_enum_rules',
|
||||
20, 2
|
||||
);
|
||||
|
||||
function wpcf7_swv_add_select_enum_rules( $schema, $contact_form ) {
|
||||
$tags = $contact_form->scan_form_tags( array(
|
||||
'basetype' => array( 'select' ),
|
||||
) );
|
||||
|
||||
$values = array_reduce(
|
||||
$tags,
|
||||
function ( $values, $tag ) {
|
||||
if ( ! isset( $values[$tag->name] ) ) {
|
||||
$values[$tag->name] = array();
|
||||
}
|
||||
|
||||
$tag_values = array_merge(
|
||||
(array) $tag->values,
|
||||
(array) $tag->get_data_option()
|
||||
);
|
||||
|
||||
if ( $tag->has_option( 'first_as_label' ) ) {
|
||||
$tag_values = array_slice( $tag_values, 1 );
|
||||
}
|
||||
|
||||
$values[$tag->name] = array_merge(
|
||||
$values[$tag->name],
|
||||
$tag_values
|
||||
);
|
||||
|
||||
return $values;
|
||||
},
|
||||
array()
|
||||
);
|
||||
|
||||
foreach ( $values as $field => $field_values ) {
|
||||
$field_values = array_map(
|
||||
static function ( $value ) {
|
||||
return html_entity_decode(
|
||||
(string) $value,
|
||||
ENT_QUOTES | ENT_HTML5,
|
||||
'UTF-8'
|
||||
);
|
||||
},
|
||||
$field_values
|
||||
);
|
||||
|
||||
$field_values = array_filter(
|
||||
array_unique( $field_values ),
|
||||
static function ( $value ) {
|
||||
return '' !== $value;
|
||||
}
|
||||
);
|
||||
|
||||
$schema->add_rule(
|
||||
wpcf7_swv_create_rule( 'enum', array(
|
||||
'field' => $field,
|
||||
'accept' => array_values( $field_values ),
|
||||
'error' => $contact_form->filter_message(
|
||||
__( "Undefined value was submitted through this field.", 'contact-form-7' )
|
||||
),
|
||||
) )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Tag generator */
|
||||
|
||||
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_menu', 25, 0 );
|
||||
|
||||
Reference in New Issue
Block a user