# double-opt-in/5.5.0/core/HTMLSelectOption.class.php

Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification, version 5.5.0. 103 lines.

- Page: https://pluginprobe.com/plugins/double-opt-in/5.5.0/code/core/HTMLSelectOption.class.php
- Raw: https://pluginprobe.com/plugins/double-opt-in/5.5.0/raw/core/HTMLSelectOption.class.php
- Modified: 2022-12-16T11:04:54+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/double-opt-in/5.5.0/code/core/HTMLSelectOption.class.php#L10-L20`.

```php
<?php

namespace forge12\contactform7\CF7DoubleOptIn {
    if (!defined('ABSPATH')) {
        exit;
    }

    /**
     * HTMLSelectOption converts an given array to a HTML Option List.
     *
     * @package forge12\contactform7\CF7DoubleOptIn
     */
    class HTMLSelectOption
    {
        /**
         * The key of the option field
         * @var string|int
         */
        private $key = '';
        /**
         * The value of the option field
         * @var string|int
         */
        private $value = '';

        /**
         * Flag if selected or not
         * @var bool
         */
        private $selected = false;

        /**
         * Create a new option list
         */
        public function __construct($key, $value, $selected = false)
        {
            $this->setKey($key);
            $this->setValue($value);
            $this->setSelected($selected);
        }

        /**
         * Return the HTML String for the option value
         * @return string
         */
        public function get()
        {
            if($this->isSelected()){
                return '<option value="' . esc_attr($this->getKey()) . '" selected="selected">' . esc_html($this->getValue()) . '</option>';
            }else{
                return '<option value="' . esc_attr($this->getKey()) . '">' . esc_html($this->getValue()) . '</option>';
            }
        }

        /**
         * @return string
         */
        public function getValue(): string
        {
            return $this->value;
        }

        /**
         * @param string $value
         */
        private function setValue(string $value)
        {
            $this->value = $value;
        }

        /**
         * @return string
         */
        public function getKey(): string
        {
            return $this->key;
        }

        /**
         * @param string $key
         */
        private function setKey(string $key)
        {
            $this->key = $key;
        }

        /**
         * @return bool
         */
        public function isSelected(): bool
        {
            return $this->selected;
        }

        /**
         * @param bool $selected
         */
        public function setSelected(bool $selected)
        {
            $this->selected = $selected;
        }
    }
}
```
