Yoast_Form::light_switch()
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.
- $buttons(массив)
- Array of two visual labels for the buttons (defaults Disabled/Enabled).
По умолчанию: [] - $reverse(true|false)
- Reverse order of buttons (default true).
По умолчанию: true - $help(строка)
- Inline Help that will be printed out before the toggle.
По умолчанию: '' - $strong(true|false)
- 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 - $attr(массив)
- Extra attributes to add to the light switch.
По умолчанию: []
Список изменений
С версии 3.1 | Введена. |
Код Yoast_Form::light_switch() 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( $variable, $label, $buttons, $this->option_name . '[' . $variable . ']', $val, $reverse, $help, $strong, $disabled_attribute ); // phpcs:ignore WordPress.Security.EscapeOutput -- Reason: All output is properly escaped or hardcoded in the presenter. echo $output; }