Yoast_Form::label()publicYoast 2.0

Output a label element.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

$Yoast_Form = new Yoast_Form();
$Yoast_Form->label( $text, $attr );
$text(строка) (обязательный)
Label text string, which can contain escaped html.
$attr(массив) (обязательный)
HTML attributes set.

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

С версии 2.0 Введена.

Код Yoast_Form::label() Yoast 22.4

public function label( $text, $attr ) {
	$defaults = [
		'class'      => 'checkbox',
		'close'      => true,
		'for'        => '',
		'aria_label' => '',
	];

	$attr       = wp_parse_args( $attr, $defaults );
	$aria_label = '';
	if ( $attr['aria_label'] !== '' ) {
		$aria_label = ' aria-label="' . esc_attr( $attr['aria_label'] ) . '"';
	}

	// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- output escaped before. Specifically, the $text variable can contain escaped html.
	echo "<label class='" . esc_attr( $attr['class'] ) . "' for='" . esc_attr( $attr['for'] ) . "'$aria_label>$text";
	if ( $attr['close'] ) {
		echo '</label>';
	}
}