Yoast_Form::textinput()publicYoast 2.0

Create a Text input field.

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

Хуков нет.

Возвращает

null. Ничего.

Использование

$Yoast_Form = new Yoast_Form();
$Yoast_Form->textinput( $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.
По умолчанию: []

Список изменений

С версии 2.0 Введена.
С версии 2.1 Introduced the $attr parameter.

Код Yoast_Form::textinput() Yoast 19.7.1

public function textinput( $variable, $label, $attr = [] ) {
	$type = 'text';
	if ( ! is_array( $attr ) ) {
		$attr = [
			'class'    => $attr,
			'disabled' => false,
		];
	}

	$defaults = [
		'placeholder' => '',
		'class'       => '',
	];
	$attr     = wp_parse_args( $attr, $defaults );
	$val      = $this->get_field_value( $variable, '' );
	if ( isset( $attr['type'] ) && $attr['type'] === 'url' ) {
		$val  = urldecode( $val );
		$type = 'url';
	}
	$attributes = isset( $attr['autocomplete'] ) ? ' autocomplete="' . esc_attr( $attr['autocomplete'] ) . '"' : '';

	$this->label(
		$label,
		[
			'for'   => $variable,
			'class' => 'textinput',
		]
	);

	$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', $attributes, $aria_attributes, ' class="', esc_attr( 'textinput ' . $attr['class'] ), '" placeholder="', esc_attr( $attr['placeholder'] ), '" type="', $type, '" id="', esc_attr( $variable ), '" 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 );
}