/home/techb158/public_html/wp-content/plugins/wpforms-lite/src/Forms/Fields/Traits
Edit: /home/techb158/public_html/wp-content/plugins/wpforms-lite/src/Forms/Fields/Traits/NumberField.php (7606B)
0 )
)
) {
$attrs['step'] = (string) $args['step'];
}
$number_label_markup = $this->field_element(
'label',
$field,
[
'slug' => $slug,
'value' => $label,
'tooltip' => $args['tooltip'] ?? '',
],
false
);
$number_input_markup = $this->field_element(
'text',
$field,
[
'type' => 'number',
'slug' => $slug,
'value' => is_numeric( $value ) ? (float) $value : '',
'attrs' => $attrs,
'class' => $args['class'] ?? '',
],
false
);
$output = $this->field_element(
'row',
$field,
[
'slug' => $slug,
'content' => $number_label_markup . $number_input_markup,
],
false
);
if ( ! $output ) {
return '';
}
if ( $echo_output ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $output;
}
return $output;
}
/**
* Helper function to create `min_max` field option markup.
*
* @since 1.9.4
*
* @param array $field Field data and settings.
* @param array $args Field preview arguments.
* @param bool $echo_output Print or return the value. Print by default.
*
* @return string
*/
private function field_number_option_min_max( $field, $args, $echo_output = true ) {
$class = $args['class'] ?? 'number_min_max';
$range_label_markup = $this->field_element(
'label',
$field,
[
'slug' => 'min',
'value' => $args['label'] ?? esc_html__( 'Range', 'wpforms-lite' ),
'tooltip' => $args['tooltip'] ?? esc_html__( 'Define the minimum and the maximum values for the field.', 'wpforms-lite' ),
],
false
);
$min_value = $field['min'] ?? null;
$input_min_args = [
'type' => 'number',
'slug' => 'min',
'value' => is_numeric( $min_value ) ? (float) $min_value : '',
'class' => $class . '-min',
'attrs' => [
'step' => 'any',
],
];
$range_input_min_markup = $this->field_element(
'text',
$field,
$input_min_args,
false
);
$max_value = $field['max'] ?? null;
$input_max_args = [
'type' => 'number',
'slug' => 'max',
'value' => is_numeric( $max_value ) ? (float) $max_value : '',
'class' => $class . '-max',
'attrs' => [
'step' => 'any',
],
];
$range_input_max_markup = $this->field_element(
'text',
$field,
$input_max_args,
false
);
return $this->field_element(
'row',
$field,
[
'slug' => 'min_max',
'content' => $range_label_markup . sprintf(
'
',
$range_input_min_markup,
(int) $field['id'],
esc_html__( 'Minimum', 'wpforms-lite' ),
$range_input_max_markup,
(int) $field['id'],
esc_html__( 'Maximum', 'wpforms-lite' )
),
],
$echo_output
);
}
/**
* Helper function to create `default_value` field option markup.
*
* @since 1.9.4
*
* @param array $field Field data and settings.
* @param array $args Field preview arguments.
* @param bool $echo_output Print or return the value. Print by default.
*
* @return string
*/
private function field_number_option_default_value( $field, $args, $echo_output = true ) {
$default_value_args = [
'slug' => 'default_value',
'label' => esc_html__( 'Default Value', 'wpforms-lite' ),
'tooltip' => esc_html__( 'Enter a default value for this field.', 'wpforms-lite' ),
'class' => $args['class'] ?? '',
'value' => $args['value'] ?? '',
'min' => $field['min'] ?? '',
'max' => $field['max'] ?? '',
'step' => $field['step'] ?? '',
];
return $this->field_number_element(
$field,
$default_value_args,
$echo_output
);
}
/**
* Helper function to create `step` field option markup.
*
* @since 1.9.4
*
* @param array $field Field data and settings.
* @param array $args Field preview arguments.
* @param bool $echo_output Print or return the value. Print by default.
*
* @return string
*/
private function field_number_option_step( $field, $args, $echo_output = true ) {
$step_args = [
'slug' => 'step',
'label' => esc_html__( 'Increment', 'wpforms-lite' ),
'tooltip' => $args['tooltip'] ?? esc_html__( 'Determines the increment between selectable values on the field.', 'wpforms-lite' ),
'class' => $args['class'] ?? '',
'min' => 0,
'step' => 'any',
'value' => 1,
];
$min = is_numeric( $field['min'] ?? null ) ? (float) $field['min'] : null;
$max = is_numeric( $field['max'] ?? null ) ? (float) $field['max'] : null;
if ( ! is_null( $min ) && ! is_null( $max ) ) {
$step_args['max'] = $max - $min;
}
return $this->field_number_element(
$field,
$step_args,
$echo_output
);
}
}