Yoast_Form::toggle_switch PHP Method

toggle_switch() public method

Create a toggle switch input field.
public toggle_switch ( string $var, array $values, string $label )
$var string The variable within the option to create the file upload field for.
$values array The radio options to choose from.
$label string The label to show for the variable.
    public function toggle_switch($var, $values, $label)
    {
        if (!is_array($values) || $values === array()) {
            return;
        }
        if (!isset($this->options[$var])) {
            $this->options[$var] = false;
        }
        if ($this->options[$var] === true) {
            $this->options[$var] = 'on';
        }
        if ($this->options[$var] === false) {
            $this->options[$var] = 'off';
        }
        $var_esc = esc_attr($var);
        echo '<div class="switch-container">';
        echo '<fieldset id="', $var_esc, '" class="fieldset-switch-toggle"><legend>', $label, '</legend>
		<div class="switch-toggle switch-candy switch-yoast-seo">';
        foreach ($values as $key => $value) {
            $key_esc = esc_attr($key);
            $for = $var_esc . '-' . $key_esc;
            echo '<input type="radio" id="' . $for . '" name="' . esc_attr($this->option_name) . '[' . $var_esc . ']" value="' . $key_esc . '" ' . checked($this->options[$var], $key_esc, false) . ' />', '<label for="', $for, '">', $value, '</label>';
        }
        echo '<a></a></div></fieldset><div class="clear"></div></div>' . "\n\n";
    }