wp2static/library/StaticHtmlOutput/Options.php

47 lines
879 B
PHP
Raw Normal View History

2016-12-27 14:30:54 +13:00
<?php
class StaticHtmlOutput_Options
{
protected $_options = array();
protected $_optionKey = null;
public function __construct($optionKey) {
2016-12-27 14:30:54 +13:00
$options = get_option($optionKey);
if (false === $options)
{
$options = array();
}
$this->_options = $options;
$this->_optionKey = $optionKey;
}
public function __set($name, $value) {
2016-12-27 14:30:54 +13:00
$this->_options[$name] = $value;
return $this;
}
public function setOption($name, $value) {
2016-12-27 14:30:54 +13:00
return $this->__set($name, $value);
}
public function __get($name) {
2016-12-27 14:30:54 +13:00
$value = array_key_exists($name, $this->_options) ? $this->_options[$name] : null;
return $value;
}
public function getOption($name) {
2016-12-27 14:30:54 +13:00
return $this->__get($name);
}
public function save() {
2016-12-27 14:30:54 +13:00
return update_option($this->_optionKey, $this->_options);
}
public function delete() {
2016-12-27 14:30:54 +13:00
return delete_option($this->_optionKey);
}
}