Yoast_Form::number
Create a Number input field.
Метод класса: Yoast_Form{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$Yoast_Form = new Yoast_Form(); $Yoast_Form->number( $variable, $label, $attr );
- $variable(строка) (обязательный)
- The variable within the option to create the text input field for.
- $label(строка) (обязательный)
- The label to show for the variable.
- $attr(массив|строка)
- Extra attributes to add to the input field. Can be class, disabled, autocomplete.
По умолчанию:[]
Код Yoast_Form::number() Yoast Form::number Yoast 27.3
public function number( $variable, $label, $attr = [] ) {
$type = 'number';
$defaults = [
'placeholder' => '',
'class' => 'number',
'disabled' => false,
'min' => 0,
'max' => 100,
];
$attr = wp_parse_args( $attr, $defaults );
$val = $this->get_field_value( $variable, 0 );
$this->label(
$label,
[
'for' => $variable,
'class' => 'textinput ' . $attr['class'],
],
);
$aria_attributes = Yoast_Input_Validation::get_the_aria_invalid_attribute( $variable );
$aria_attributes .= Yoast_Input_Validation::get_the_aria_describedby_attribute( $variable );
$disabled_attribute = $this->get_disabled_attribute( $variable, $attr );
// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: $disabled_attribute output is hardcoded and all other output is properly escaped.
echo '<input' . $aria_attributes . ' class="' . esc_attr( $attr['class'] ) . '" type="' . $type . '" id="', esc_attr( $variable ), '" min="', esc_attr( $attr['min'] ), '" max="', esc_attr( $attr['max'] ), '" name="', esc_attr( $this->option_name . '[' . $variable . ']' ), '" value="', esc_attr( $val ), '"', $disabled_attribute, '/>', '<br class="clear" />';
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped in getter.
echo Yoast_Input_Validation::get_the_error_description( $variable );
}