'manage_options', 'sanitize_callback' => array($this, 'sanitize'), 'sections' => array(), 'fields' => array(), 'parent_slug' => 'options-general.php', 'icon_url' => '', 'position' => null ), $options); $this->registry = $options; } /** * Adds a new section * * @param Section $section * @return SettingsPage */ public function addSection(Section $section) { $this->registry['sections'][] = $section; $this->currentSection = $section; return $this; } /** * Adds a field * * @param Field $field * @return SettingsPage */ public function addField(Field $field) { $field ->setSection($this->currentSection) ->setOptionName($this->registry['option_name']) ; if (isset($this->registry['field_values'][$field->getId()])) { $field->setValue($this->registry['field_values'][$field->getId()]); } $this->registry['fields'][] = $field; return $this; } /** * Shortcut method to add form error/update notices via add_settings_error() * * @param $code * @param $message * @param string $type */ public function addError($code, $message, $type = 'error') { add_settings_error($this->registry['option_name'], $code, $message, $type); } /** * Returns the value of option * * @param string $name Name of option * @param mixed $default Default value * @return array|mixed|null Value of option */ public function getOption($name, $default = null) { $data = new Data((array)get_option($this->registry['option_name'])); return $data->get($name, $default); } /** * Method for sanitize_callback option. * Override to add your own sanitization/validation logic. * * @param $input * @return mixed */ public function sanitize($input) { return $input; } /** * Renders settings page */ public function render() { $reg = $this->registry; ?>