Skip to content

Commit 173f5a7

Browse files
committed
Add SettingsPage::getOption() method
It supports dot notation access for deep option structures.
1 parent 8e8a953 commit 173f5a7

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
],
1111
"require": {
1212
"php": ">=5.3.2",
13-
"doctrine/annotations": "1.*"
13+
"doctrine/annotations": "1.*",
14+
"dflydev/dot-access-data": "~1.0"
1415
},
1516
"autoload": {
1617
"psr-0": {"Oow": "lib/"}
1718
}
18-
}
19+
}

lib/Oow/Settings/SettingsPage.php

+14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Oow\Settings;
44

5+
use Dflydev\DotAccessData\Data;
56
use Oow\Settings\Field\Field;
67

78
/** @Plugin */
@@ -83,6 +84,19 @@ public function addError($code, $message, $type = 'error')
8384
add_settings_error($this->registry['option_name'], $code, $message, $type);
8485
}
8586

87+
/**
88+
* Returns the value of option
89+
*
90+
* @param string $name Name of option
91+
* @param mixed $default Default value
92+
* @return array|mixed|null Value of option
93+
*/
94+
public function getOption($name, $default = null)
95+
{
96+
$data = new Data((array)get_option($this->registry['option_name']));
97+
return $data->get($name, $default);
98+
}
99+
86100
/**
87101
* Method for sanitize_callback option.
88102
* Override to add your own sanitization/validation logic.

0 commit comments

Comments
 (0)