PluginProbe
The GDPR Framework By Data443 / trunk
The GDPR Framework By Data443 vtrunk
2.5.0 2.4.0 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.3 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.39 1.0.4 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 All 41 releases
gdpr-framework / src / Options / Options.php

Options.php in The GDPR Framework By Data443 trunk, at src/Options/Options.php

66 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Codelight\GDPR\Options;
4
5 /**
6 * Main class for handling options on a non-multisite install.
7 * Adapted from https://carlalexander.ca/designing-classes-wordpress-options-api/
8 *
9 * Class Options
10 *
11 * @package Codelight\GDPR\Options
12 */
13 class Options extends OptionsBase
14 {
15 /**
16 * Gets the option for the given name. Returns the default value if the value does not exist.
17 *
18 * @param string $name
19 * @param mixed $default
20 *
21 * @return mixed
22 */
23 public function get($name, $default = null, $enableFilter = true)
24 {
25 $value = get_option($this->prefix($name), $default);
26
27 if ($enableFilter) {
28 $value = apply_filters("gdpr/options/get/{$name}", $value);
29 }
30
31 if (is_array($default) && !is_array($value)) {
32 $value = (array) $value;
33 }
34
35 return $value;
36 }
37
38 /**
39 * Sets an option. Overwrites the existing option if the name is already in use.
40 *
41 * @param string $name
42 * @param mixed $value
43 */
44 public function set($name, $value, $enableFilter = true)
45 {
46 if ($enableFilter) {
47 $value = apply_filters("gdpr/options/set/{$name}", $value, get_option($this->prefix($name)));
48 }
49
50 update_option(
51 $this->prefix($name),
52 $value,
53 false
54 );
55 }
56
57 /**
58 * Removes the option with the given name.
59 *
60 * @param string $name
61 */
62 public function delete($name)
63 {
64 delete_option($this->prefix($name));
65 }
66 }