XF 2.2 Set default guest username

Fionn

Member
I want the "user" field to display the default value "anonymous" when an anonymous user is making a post. I also want the user to be able to enter a custom name if they prefer. Is this possible without a custom addon?
 
I do have an addon that is supposed to handle this but it is not working for post replies. It does work for new threads.

The code in src/addons/.../XF/Service/Thread/Creator.php is:

<?php

namespace FS\AnonymousUser\XF\Service\Thread;

class Creator extends XFCP_Creator
{
protected function setUser(\XF\Entity\User $user)
{
parent::setUser($user);

if ($user->user_id == 0) {
$this->thread->username = "anonymous";
$this->post->username = "anonymous";
}
}
}
 
Back
Top Bottom