Yoast_Form::show_hide_switch()publicYoast 1.0

Creates a toggle switch to show hide certain options.

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

Хуков нет.

Возвращает

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

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

$Yoast_Form = new Yoast_Form();
$Yoast_Form->show_hide_switch( $variable, $label, $inverse_keys, $help, $attr );
$variable(строка) (обязательный)
The variable within the option to create the radio buttons for.
$label(строка) (обязательный)
The visual label for the radio buttons group, used as the fieldset legend.
$inverse_keys(true|false)
Whether or not the option keys need to be inverted to support older functions.
По умолчанию: false
$help(строка)
Inline Help that will be printed out before the visible toggles text.
По умолчанию: ''
$attr(массив)
Extra attributes to add to the show-hide switch.
По умолчанию: []

Код Yoast_Form::show_hide_switch() Yoast 22.4

public function show_hide_switch( $variable, $label, $inverse_keys = false, $help = '', $attr = [] ) {
	$defaults = [
		'disabled' => false,
	];
	$attr     = wp_parse_args( $attr, $defaults );

	$on_key  = ( $inverse_keys ) ? 'off' : 'on';
	$off_key = ( $inverse_keys ) ? 'on' : 'off';

	$show_hide_switch = [
		$on_key  => __( 'On', 'wordpress-seo' ),
		$off_key => __( 'Off', 'wordpress-seo' ),
	];

	$is_disabled = ( isset( $attr['disabled'] ) && $attr['disabled'] );

	$this->toggle_switch(
		$variable,
		$show_hide_switch,
		$label,
		$help,
		[ 'disabled' => $is_disabled ]
	);
}