# simpleanalytics/1.67/src/Settings/Blocks/Fields/Checkbox.php

Simple Analytics, version 1.67. 72 lines.

- Page: https://pluginprobe.com/plugins/simpleanalytics/1.67/code/src/Settings/Blocks/Fields/Checkbox.php
- Raw: https://pluginprobe.com/plugins/simpleanalytics/1.67/raw/src/Settings/Blocks/Fields/Checkbox.php
- Modified: 2024-11-21T15:59:46+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/simpleanalytics/1.67/code/src/Settings/Blocks/Fields/Checkbox.php#L10-L20`.

```php
<?php

namespace SimpleAnalytics\Settings\Blocks\Fields;

use SimpleAnalytics\Setting;
use SimpleAnalytics\Settings\Concerns\HasDocs;
use SimpleAnalytics\UI\LabelComponent;

class Checkbox extends Field
{
    use HasDocs;

    /**
     * @var bool
     */
    protected $default = false;

    public function getValueSanitizer(): callable
    {
        return 'absint';
    }

    public function getValueType(): string
    {
        return 'integer';
    }

    public function default(bool $value): self
    {
        $this->default = $value;

        return $this;
    }

    public function render(): void
    {
        ?>
        <div class="relative flex gap-x-3">
            <div class="flex h-6 items-center">
                <input
                    id="<?php 
        echo esc_attr($this->getKey());
        ?>"
                    name="<?php 
        echo esc_attr($this->getKey());
        ?>"
                    type="checkbox"
                    value="1"
                    class="h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary"
                    <?php 
        if (Setting::boolean($this->getKey(), $this->default) === true) echo 'checked';
        ?>
                >
            </div>
            <div class="text-sm leading-6">
                <?php 
        (new LabelComponent($this->getLabel(), $this->docs, $this->getKey()))();
        ?>

                <?php 
        if ($this->description): ?>
                    <p class="text-gray-500">
                        <?php echo esc_html($this->description); ?>
                    </p>
                <?php endif;
        ?>
            </div>
        </div>
        <?php 
    }
}

```
