Yoast_Form::number()publicYoast 1.0

Create a Number input field.

{} Это метод класса: Yoast_Form{}

Хуков нет.

Возвращает

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 19.7.1

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 );

	Yoast_Input_Validation::set_error_descriptions();
	$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 );
}