3b5668b0 by Chris Boden

Added defaults option

1 parent 53f8033a
1 <?php 1 <?php
2 /*
3 * I made a boo boo
4 * This only works with Array variables
5 */
2 class WP_Option implements ArrayAccess, Countable { 6 class WP_Option implements ArrayAccess, Countable {
3 private $_ns; 7 private $_ns;
4 private $_data = Array(); 8 private $_data = Array();
5 9
6 public function __construct($ns) { 10 public function __construct($ns, $defaults = null) {
7 $this->_ns = $ns; 11 $this->_ns = $ns;
8 $this->_data = get_option($ns); 12 $this->_data = get_option($ns);
13
14 if (!is_null($defaults) && is_array($defaults)) {
15 foreach ($this->_data as $key => $val) {
16 $defaults[$key] = $val;
17 }
18
19 if ($this->_data != $defaults) {
20 $this->_data = $defaults;
21 $this->save();
22 }
23 }
9 } 24 }
10 25
11 public function offsetExists($var) { 26 public function offsetExists($var) {
......