To my knowledge, the Answers module (you know the drill .. Disclosure: I'm a co-maintainer) does not have such setting that you were looking for. However, by using the Rules module (also), you should be able to get this to work, as further detailed below ...
Step 1: Create a (blocked) user 'Somebody'
Create an extra user with a user name that will be shown instead of the user name that you want to appear anonymous. I decided to name such user "Somebody", and it was created with uid=68
. Moreover, I decided to make it a blocked user (not to be used for any other purpose).
Step 2: Add a dedicated field to relevant content types
For every content type for which you want this facility to be available (e.g for types Question and Answer), add an extra field that an editor (author) of a node can use to indicate if the node should appear anonymous.
In my case I have a selection list field with machine name field_optionlist
and which has 2 possible values, like so:
- A (= Appear anonymous).
- S (= Standard author display).
Step 3: Create a custom rule
Below is custom rule (in Rules export format) that will set the node author to "Somebody" (= the user name from Step 1) whenever value "A" is selected via the dedicated field from Step 2 (and whenever a node of type Question or Answer is saved):
{ "rules_optionally_hide_node_author" : {
"LABEL" : "Optionally hide node author",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"ON" : { "node_presave" : [] },
"IF" : [
{ "node_is_of_type" : {
"node" : [ "node" ],
"type" : { "value" : {
"answers_answer" : "answers_answer",
"answers_question" : "answers_question"
}
}
}
},
{ "entity_has_field" : { "entity" : [ "node" ], "field" : "field_optionlist" } },
{ "data_is" : { "data" : [ "node:field-optionlist" ], "value" : "A" } }
],
"DO" : [
{ "entity_fetch" : {
"USING" : { "type" : "user", "id" : "68" },
"PROVIDE" : { "entity_fetched" : { "user_fetched" : "Fetched user" } }
}
},
{ "data_set" : { "data" : [ "node:author" ], "value" : [ "user-fetched" ] } }
]
}
}
Adapt the uid=68
value in the above rule to fit your dedicated user, and replace the machine name of field_optionlist
to fit your case (prior to trying to import the above rule).
That's it ... at least to make it work in my setup.
Step 4: Extra refinements
For the sake of completeness, you should create a variation of this custom rule to set the node author to "current user" whenever the field value is different from "A".
Bonus feature ...
By using the above approach, and by using a user name like Wiki
, you can implement logic that is pretty close to "wiki" questions / answers on SE-sites also. Because for those kinds of questions/answers the original author will not have any user points (like reputation) changes anymore for any upvotes or downvotes of such question or answer.
<?php if ($display_submitted): ?>
then looking at line 18$display_submitted: Whether submission information should be displayed
. Seems like this module already has this feature?