Add `$userID` parameter to `isAccessible` in `UserProfile`
authorCyperghost <olaf_schmitz_1@t-online.de>
Fri, 22 Mar 2024 10:50:51 +0000 (11:50 +0100)
committerCyperghost <olaf_schmitz_1@t-online.de>
Fri, 22 Mar 2024 10:50:51 +0000 (11:50 +0100)
wcfsetup/install/files/lib/data/user/UserProfile.class.php

index 9c355ac02e1025ee4403d230d6484364c3f25ef1..1bf38302ff283c16c689d1cef52d7a5ff28d950b 100644 (file)
@@ -735,14 +735,14 @@ class UserProfile extends DatabaseObjectDecorator implements ITitledLinkObject
 
     /**
      * Returns true if current user fulfills the required permissions.
-     *
-     * @param string $name
-     * @return  bool
      */
-    public function isAccessible($name)
+    public function isAccessible(string $name, int $userID = null): bool
     {
         /** @noinspection PhpVariableVariableInspection */
         $data = ['result' => true, 'name' => $name];
+        if ($userID === null) {
+            $userID = WCF::getUser()->userID;
+        }
 
         switch ($this->{$name}) {
             case self::ACCESS_EVERYONE:
@@ -750,15 +750,15 @@ class UserProfile extends DatabaseObjectDecorator implements ITitledLinkObject
                 break;
 
             case self::ACCESS_REGISTERED:
-                $data['result'] = (WCF::getUser()->userID ? true : false);
+                $data['result'] = ($userID ? true : false);
                 break;
 
             case self::ACCESS_FOLLOWING:
                 $result = false;
-                if (WCF::getUser()->userID) {
-                    if (WCF::getUser()->userID == $this->userID) {
+                if ($userID) {
+                    if ($userID == $this->userID) {
                         $result = true;
-                    } elseif ($this->isFollowing(WCF::getUser()->userID)) {
+                    } elseif ($this->isFollowing($userID)) {
                         $result = true;
                     }
                 }