Anon accounts?

Is there a plan to add the ability to post as Anonymous?

I’m not sure it’s really necessary. ppl can register a 2nd account if they want a different identity, though that might be prohibitive at $20 (e.g., ppl probably wouldn’t have a different account for each thread)

Discourse has built in anonymous posting features. You must post and read the forum a bit to increase your trust level before you get access to it.

Basically you can switch to anon in your user menu:

And can switch back. If you do not use an anon account for 7 days (current and default value), you can never access it again, and when you switch anon you’ll get a new anon account. They get named stuff like Anonymous4.

Figuring out who an anonymous account belongs to requires database access. It’s not visible from the admin UI (except indirectly via tools like seeing that an anon account used the same ip address as another account).

To enter anonymous mode, you need trust level 2. See:

Also, currently, there’s no way to automatically let anonymous users through the paywall to write posts. I made an anonymous users group with posting permission but can’t auto-add people to it. You can add people to a group based on email address domain and all anon accounts have the same one, but it doesn’t trigger when anon accounts are created (I guess because they don’t use the regular account creation process). Saving the group settings gives posting permission to all existing anon accounts, so currently an admin has to be asked to do that, though you don’t have to say which anon account is yours since they don’t need to add yours individually, and you could anonymously contact an admin by email or something if you wanted. (If you can figure out a better solution, please share!)

I asked a question about this on the support Discourse but have not gotten an answer as of yet. My impression is that they don’t consider it a bug and were at least considering adding it as a feature but that was the status as of some time in 2020, so I don’t think it’s an action item for them

I’m sure we could automate giving posting permissions to all anon accounts daily (or more often) with a cron job or something (on the server or on an admin’s computer), but it’d be nice if new anon accounts could post immediately.

Here’s some plugin code that will trigger automatic group membership for anon users on account creation or login:

# frozen_string_literal: true

# name: CfAnonSchedule
# about: Regularly add anon accounts to a group
# version: 0.1
# authors: xertrov
# url:

register_asset 'stylesheets/common/cf-anon-schedule.scss'
register_asset 'stylesheets/desktop/cf-anon-schedule.scss', :desktop
register_asset 'stylesheets/mobile/cf-anon-schedule.scss', :mobile

enabled_site_setting :cf_anon_schedule_enabled

PLUGIN_NAME ||= 'CfAnonSchedule'

load File.expand_path('lib/cf-anon-schedule/engine.rb', __dir__)

after_initialize do

  require_dependency 'discourse_event'

  [:users_created, :user_logged_in].each do |event|
    DiscourseEvent.on(event) do |user|
      if SiteSetting.cf_anon_schedule_enabled
        if user.anonymous?

There’s a bit more to it than that (a settings.yaml file with the enabled setting), but otherwise it’s just the default plugin that gets generated via rails g plugin. I can polish it up a bit (like removing scss stuff) and push to a github repo if there’s interest in using it.

I have only done some basic, manual tests w/ it, but it seems to work for both logging in with an existing anon user + on the creation of a new anon user.

Edit: I initially planned to do like a scheduled thing, but this seems more elegant.

Edit2: it presumes you have the group > membership > automatic setting configured.


Cool, thanks, yeah if you put it on github i’ll install it.

why do it at login and creation both?

I added :users_created first, then :user_logged_in (as I was playing around looking through other plugin code). I guess that when a new anon account is made it should trigger both (because you login immediately after). So it’s just an artifact of my dev order. I’ll remove it when I polish up before pushing.

I think I might skip the anon check and just call user.set_automatic_groups for all users that log in. that way if there’s any other automatic group stuff later, it’ll start working when users log out and then log in again.

i think (without testing) that automatic group stuff already works with other accounts when they’re created. if it didn’t, i don’t know what they’d even mean by automatic. i think the issue is just that anon accounts aren’t created through the normal creation process.


I think cd discourse/plugins && git clone and a restart of discourse should be enough to get it working. I tested it on a dev instance of discourse and everything seemed to work fine.

I left the if user.anonymous? test in. If there’s ever a reason to change that later on, it’s not like the plugin is that complex.

1 Like

How come it triggers on login not user creation? Did the creation event not work?

Also the anonymous check is important because I’m adding them to an Anonymous Users group!

Doing it on login means that existing anon users that aren’t in the right auto-groups would get added when they next logged in - IMO that’s more robust which is why I didn’t think much about using the user creation event.

It also means that if you need to change something (like make a new auto-group or w/e) then existing anon users will get added to it, not just new ones.

But also, IDK if the user creation event worked b/c every test I did was creation + login (i.e. the ‘go anonymous’ link). But I know the login event worked because some anon users I tested already existed.

The group is never mentioned in the plugin, it just adds a user to any auto-groups their email domain matches. I don’t see why the anon check really matters because no one else has auto-groups (like, calling user.set_automatic_groups on my use wouldn’t add me to the anon group).

Maybe it wasn’t clear in my original snippet, but that snippet is basically the whole plugin. the other files and stuff are boilerplate (I removed frontend stuff, the other stuff might matter so I left it in). the functions and stuff I’m calling are from Discourse.

that’s not useful. it’s already got that kind of robustness: saving settings will auto-add all anons to the automatic groups.

oic, so non-anons won’t match anyway.

Ahh, that makes sense.


I’ll patch in a few hours (It’s just swapping :users_created and :user_logged_in in plugin.rb).

ok. plz confirm that actually works tho. cuz the issue is anons do not get auto-added to the group when created via someone entering anonymous mode, so i’m not sure what events actually get fired in that case.

It works with :user_created. For whatever reason I had :users_created before (plural), which I’m fairly sure I copied from somewhere – that one doesn’t work.

Anyway, updated git repo.

screenshot of some testing – the missing anon users confirmed that it doesn’t work normally + :users_created doesn’t work

1 Like