Modifying username when submitting posts

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
Appaulling
Registered User
Posts: 8
Joined: Mon Mar 11, 2019 9:33 pm

Modifying username when submitting posts

Post by Appaulling »

Hi,
I am trying to find a way to change the username when submitting posts, so that you can be logged in as "A" but write posts as "Anonymous1234". However, so far all my attempts to do so have not worked out. Subscribing to "submit_post_data" and setting the user_id does not work, because later phpBB simply overrides this with $user->data['user_id']. Trying to change the SQL also does not work, because as far as I can see there is no event that allows overriding the last_poster_name that is also stored in the topics table. So as far as I can see the best way to do this would be to override $user->data['user_id'] for the submit_post function. Is there a way to do this?
User avatar
EA117
Registered User
Posts: 1818
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: Modifying username when submitting posts

Post by EA117 »

For what it's worth, one extension I can think of which does this is the "Contact Admin" extension. It has the ability to post the contact forms as messages in a forum, using a designated user account you've specified in the extension configuration. So they would effectively be in a session where the actual user is Guest/anonymous, but posting a message as though they were the user account that had been specified. While waiting for other programmatic advice, you might want to look at their code to see what ideas you glean from that.
User avatar
mrgoldy
Development Team Member
Development Team Member
Posts: 1393
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: Modifying username when submitting posts

Post by mrgoldy »

Well, this is not what phpBB was designed for, so yes it is not that easily doable.
There are ways of doing it, but they are susceptible to bugs and errors.
This will require overloading the $user and $auth objects.

You can have a look at the "Linked Accounts" extension, that does something similar.

But once again, tread carefully!
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
Post Reply

Return to “Extension Writers Discussion”