Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
in Q2A Core by
I'd like for unanswered questions to be visible only to logged-in users, to prevent off-color/abusive content from appearing to the public. Is there any way to accomplish this?

2 Answers

+1 vote
Moderation will be part of the next release - that should help you with that and achieve exactly what you want! In the mean time, you could hook yourself to the event thrown when question are created and set them as hidden - only admin will then see them.

Another option for you would be to create your own theme and when outputing question list, you could ignore all those that are unswered for not logged in users.

Finally, built in right now and with no coding involved, you can only go to Permissions and decide to show your questions (all of them) only to registered users.
That's great to hear about moderation coming--that would be the ideal solution. The last option is easy but it won't work, since I do need the public to see the questions that have been answered.

Is there any way you or someone else could explain, more or less step-by-step, how to do either of the other solutions--set created questions as hidden or output only answered questions for not logged in users? I can sort of read PHP in very small doses, but I'm far from a programmer.
0 votes
edited by

If you use the "theme" solution, unanswered question would be not be shown but this will have some side effects on paging (the paging counts all questions while you would only show the answered one; so some page might be empty and all pages won't be the same size) - but as a temp and simple solution until the next version, I think this would work out. First check out how to create your custom advanced theme here (http://www.question2answer.org/themes.php#advanced) - (really simple) and in your qa-theme.php write this:

function main()
if (isset($this->content['q_list']['qs'])  && qa_get_logged_in_userid() == null) {
foreach($qs as $question_idx => $question) {
if ($question['answers_raw'] == 0) {
$this->content['q_list']['qs'] = $qs;
The event solution is a bit more complex, but you can look in the plugin - events to  see how to do it here http://www.question2answer.org/plugins.php . 
My bad, a reference problem. When I tested it I wasn't calling back the parent method. See the modified version which I've tested in the Candy theme and worked fine.
Hm, didn't work. I got

Notice: Undefined index: qs in /home/[path]/qa-include/qa-theme-base.php on line 1046

Warning: Invalid argument supplied for foreach() in /home/[path]/qa-include/qa-theme-base.php on line 1046

And no questions appeared at all.  Again, it's quite possible I made some other mistake here.
Sorry, copy paste issue I think! :) New version!
Perfect, it works now! Many thanks.