user = $user; // this should rather be coming from the user object $this->kirby = kirby::instance(); // try to find the avatar if($file = f::resolve($this->kirby->roots()->avatars() . DS . $user->username(), ['jpg', 'jpeg', 'gif', 'png'])) { $filename = f::filename($file); } else { $filename = $user->username() . '.jpg'; $file = $this->kirby->roots()->avatars() . DS . $filename; } parent::__construct($file, $this->kirby->urls()->avatars() . '/' . $filename); } }