| | |
| | | } |
| | | |
| | | trait UserConnection { |
| | | use _Base; |
| | | protected function determineUser():void |
| | | { |
| | | if (current_user_can('manage_options')) { |
| | |
| | | } |
| | | public function switchUser(?int $userID = null):bool |
| | | { |
| | | if (!$this->userCanConnect($userID)) { |
| | | if (!is_null($userID) && !$this->userCanConnect($userID)) { |
| | | return false; |
| | | } |
| | | $this->clearUser(); |
| | |
| | | $this->initializeRateLimiters(); |
| | | return true; |
| | | } |
| | | protected function determineUserID(int $userID):bool|int |
| | | { |
| | | if (!$this->userCanConnect($userID)) { |
| | | return false; |
| | | } |
| | | return $userID; |
| | | } |
| | | protected function clearUser():void |
| | | { |
| | | $this->userID = false; |
| | | $this->credentials = []; |
| | | if (property_exists($this, 'rateLimiter')) { |
| | | $this->requestLimiter?->saveHistory(); |
| | | $this->requestLimiter = null; |