Yoast_Form::light_switch PHP Method

light_switch() public method

Create a light switch input field.
public light_switch ( string $var, string $label, array $buttons = [], boolean $reverse = true )
$var string The variable within the option to create the checkbox for.
$label string The label to show for the variable.
$buttons array Array of two labels for the buttons (defaults Off/On).
$reverse boolean Reverse order of buttons (default true).
    public function light_switch($var, $label, $buttons = array(), $reverse = true)
    {
        if (!isset($this->options[$var])) {
            $this->options[$var] = false;
        }
        if ($this->options[$var] === true) {
            $this->options[$var] = 'on';
        }
        $class = 'switch-light switch-candy switch-yoast-seo';
        $aria_labelledby = esc_attr($var) . '-label';
        if ($reverse) {
            $class .= ' switch-yoast-seo-reverse';
        }
        if (empty($buttons)) {
            $buttons = array(__('Disabled', 'wordpress-seo'), __('Enabled', 'wordpress-seo'));
        }
        list($off_button, $on_button) = $buttons;
        echo '<div class="switch-container">', '<label class="', esc_attr($class), '"><b class="switch-yoast-seo-jaws-a11y">&nbsp;</b>', '<input type="checkbox" aria-labelledby="', $aria_labelledby, '" id="', esc_attr($var), '" name="', esc_attr($this->option_name), '[', esc_attr($var), ']" value="on"', checked($this->options[$var], 'on', false), '/>', "<b class='label-text' id='{$aria_labelledby}'>{$label}</b>", '<span aria-hidden="true">
			<span>', esc_html($off_button), '</span>
			<span>', esc_html($on_button), '</span>
			<a></a>
		 </span>
		 </label><div class="clear"></div></div>';
    }