Yoast_Form::light_switch()publicYoast 3.1

Create a light switch input field using a single checkbox.

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

Хуков нет.


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


$Yoast_Form = new Yoast_Form();
$Yoast_Form->light_switch( $variable, $label, $buttons, $reverse, $help, $strong, $attr );
$variable(строка) (обязательный)
The variable within the option to create the checkbox for.
$label(строка) (обязательный)
The visual label text for the toggle.
Array of two visual labels for the buttons (defaults Disabled/Enabled).
По умолчанию: []
Reverse order of buttons (default true).
По умолчанию: true
Inline Help that will be printed out before the toggle.
По умолчанию: ''
Whether the visual label is displayed in strong text. Starting from Yoast SEO 16.5, the visual label is forced to bold via CSS.
По умолчанию: false
Extra attributes to add to the light switch.
По умолчанию: []

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

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

Код Yoast_Form::light_switch() Yoast 21.6

public function light_switch( $variable, $label, $buttons = [], $reverse = true, $help = '', $strong = false, $attr = [] ) {
	$val = $this->get_field_value( $variable, false );

	$defaults = [
		'disabled' => false,
	$attr     = wp_parse_args( $attr, $defaults );

	if ( $val === true ) {
		$val = 'on';

	$disabled_attribute = $this->get_disabled_attribute( $variable, $attr );

	$output = new Light_Switch_Presenter(
		$this->option_name . '[' . $variable . ']',

	// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: All output is properly escaped or hardcoded in the presenter.
	echo $output;