# gdpr-framework/2.1.0/src/Options/OptionsBase.php

The GDPR Framework By Data443, version 2.1.0. 71 lines.

- Page: https://pluginprobe.com/plugins/gdpr-framework/2.1.0/code/src/Options/OptionsBase.php
- Raw: https://pluginprobe.com/plugins/gdpr-framework/2.1.0/raw/src/Options/OptionsBase.php
- Modified: 2021-08-02T13:49:42+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/gdpr-framework/2.1.0/code/src/Options/OptionsBase.php#L10-L20`.

```php
<?php

namespace Codelight\GDPR\Options;

/**
 * Parent class for options.
 * Adapted from https://carlalexander.ca/designing-classes-wordpress-options-api/
 *
 * Class OptionsBase
 *
 * @package Codelight\GDPR\Options
 */
abstract class OptionsBase
{
    /* @var string */
    protected $prefix = 'gdpr_';

    /**
     * Auto-prefix all options
     *
     * @param $name
     * @return string
     */
    public function prefix($name)
    {   
        // Check for accidental duplicate prefix
        if ("" === strpos($name, $this->prefix)) {
            trigger_error("You appear to have a duplicate prefix for option {$name}", E_USER_NOTICE);
            return $name;
        }

        return $this->prefix . $name;
    }

    /**
     * Checks if the option with the given name exists or not.
     *
     * @param string $name
     *
     * @return bool
     */
    public function has($name)
    {
        return null !== $this->get($name);
    }

    /**
     * Gets the option for the given name. Returns the default value if the value does not exist.
     *
     * @param string $name
     * @param mixed  $default
     *
     * @return mixed
     */
    abstract public function get($name, $default = null);

    /**
     * Removes the option with the given name.
     *
     * @param string $name
     */
    abstract public function delete($name);

    /**
     * Sets an option. Overwrites the existing option if the name is already in use.
     *
     * @param string $name
     * @param mixed  $value
     */
    abstract public function set($name, $value);
}
```
