wpcf7_swv_add_number_rules()
Хуков нет.
Возвращает
null. Ничего (null).
Использование
wpcf7_swv_add_number_rules( $schema, $contact_form );
- $schema(обязательный)
- .
- $contact_form(обязательный)
- .
Код wpcf7_swv_add_number_rules() wpcf7 swv add number rules CF7 6.1.7
function wpcf7_swv_add_number_rules( $schema, $contact_form ) {
$tags = $contact_form->scan_form_tags( array(
'basetype' => array( 'number', 'range' ),
) );
foreach ( $tags as $tag ) {
if ( $tag->is_required() ) {
$schema->add_rule(
wpcf7_swv_create_rule( 'required', array(
'field' => $tag->name,
'error' => wpcf7_get_message( 'invalid_required' ),
) )
);
}
$schema->add_rule(
wpcf7_swv_create_rule( 'number', array(
'field' => $tag->name,
'error' => wpcf7_get_message( 'invalid_number' ),
) )
);
$min = $tag->get_option( 'min', 'signed_num', true );
$max = $tag->get_option( 'max', 'signed_num', true );
if ( 'range' === $tag->basetype ) {
if ( ! wpcf7_is_number( $min ) ) {
$min = '0';
}
if ( ! wpcf7_is_number( $max ) ) {
$max = '100';
}
}
if ( wpcf7_is_number( $min ) ) {
$schema->add_rule(
wpcf7_swv_create_rule( 'minnumber', array(
'field' => $tag->name,
'threshold' => $min,
'error' => wpcf7_get_message( 'number_too_small' ),
) )
);
}
if ( wpcf7_is_number( $max ) ) {
$schema->add_rule(
wpcf7_swv_create_rule( 'maxnumber', array(
'field' => $tag->name,
'threshold' => $max,
'error' => wpcf7_get_message( 'number_too_large' ),
) )
);
}
}
}