user = $user; } /** * Return the user ID * * @return void */ private function setupUuid() { $uuid = \get_user_meta($this->user->ID, $this->key . 'uuid', true); if (!$uuid) { $id = \wp_hash(\wp_json_encode($this->user)); \update_user_meta($this->user->ID, $this->key . 'uuid', $id); } $this->uuid = $uuid; } /** * Returns data about the user * Use it like User::data('ID') to get the user id * * @param string $arguments - Right now a string of arguments, like ID. * @return mixed - Data about the user. */ private function dataHandler($arguments) { // Right now assume a single argument, but could expand to multiple. if (isset($this->user->$arguments)) { return $this->user->$arguments; } return \get_user_meta($this->user->ID, $this->key . $arguments, true); } /** * Allows to dynamically setup the user with uuid * Use it like User::data('ID') to get the user id * * @param string $name - The name of the method to call. * @param array $arguments - The arguments to pass in. * * @return mixed */ public static function __callStatic($name, array $arguments) { $name = "{$name}Handler"; if (is_null(self::$instance)) { require_once ABSPATH . 'wp-includes/pluggable.php'; self::$instance = new static(\wp_get_current_user()); $r = self::$instance; $r->setupUuid(); } $r = self::$instance; return $r->$name(...$arguments); } }