6ead7a0c by Marty Penner

Ensure the User metacache is updated when a meta field is set

1 parent 9e90ca86
...@@ -7,7 +7,7 @@ class User { ...@@ -7,7 +7,7 @@ class User {
7 public $id = 0; 7 public $id = 0;
8 8
9 protected $_wpuser; 9 protected $_wpuser;
10 public $_metacache = Array(); // should be protected, need to figure out how invisible byte works with serialize and not using base64 encode 10 public $_metacache = []; // should be protected, need to figure out how invisible byte works with serialize and not using base64 encode
11 11
12 public function __construct($id, $name = '', $blog_id = '') { 12 public function __construct($id, $name = '', $blog_id = '') {
13 $this->_wpuser = new WP_User($id, $name, $blog_id); 13 $this->_wpuser = new WP_User($id, $name, $blog_id);
...@@ -22,12 +22,20 @@ class User { ...@@ -22,12 +22,20 @@ class User {
22 return $this->getMeta($key, true); 22 return $this->getMeta($key, true);
23 } 23 }
24 24
25 /**
26 * Magically set a meta value and persist it to the store.
27 *
28 * @param $key
29 * @param $val
30 */
25 public function __set($key, $val) { 31 public function __set($key, $val) {
26 $this->setMeta($key, $val); 32 $this->setMeta($key, $val);
33 // Update the meta cache
34 $this->_metacache[$key] = $val;
27 } 35 }
28 36
29 public function __sleep() { 37 public function __sleep() {
30 return Array('_metacache', 'id', 'ID'); 38 return ['_metacache', 'id', 'ID'];
31 } 39 }
32 40
33 public function __wakeup() { 41 public function __wakeup() {
...@@ -46,7 +54,7 @@ class User { ...@@ -46,7 +54,7 @@ class User {
46 public function __call($method, $params) { 54 public function __call($method, $params) {
47 if (method_exists($this->_wpuser, $method)) { 55 if (method_exists($this->_wpuser, $method)) {
48 $this->setUser(); 56 $this->setUser();
49 return call_user_func_array(Array($this->_wpuser, $method), $params); 57 return call_user_func_array([$this->_wpuser, $method], $params);
50 } 58 }
51 59
52 $classname = get_class($this->_wpuser); 60 $classname = get_class($this->_wpuser);
......