Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

Is it too late to offer a badge plugin?

+21 votes
asked Jul 30, 2011 in Plugins by NoahY
edited Nov 28, 2011 by NoahY
Just wondering whether someone else has already made headway on a badges plugin.  I've created a working prototype with a single badge that creates two databases, one for badge types, one for user-earned badges, checks for whether a badge is warranted on an event, awards the badge, and stores a notify flag, giving a notice when the recipient loads a page.  It also implements a table on the user profile page to show which badges have been earned, and number of each.
commented Feb 16, 2013 by Hiroshi Rana
Badge widget not displaying correctly at two places

Plugin Options:
1- Show badge widget beside points in user meta
(does not show up)
2- Show badge widget beside points in question list
gives an error something like Undefined index:  .......qa-include/qa-app-format.php(1466) : eval()'d code - at user profile in recent activity questions.
Also page for badges is not displaying correctly.

I am using latest version of this plugin with Q2A 1.5.4.

Great great plugin but needs fixes.

commented Feb 22, 2013 by IamRobin
same here in 1.5.4

27 Answers

+1 vote
answered Jul 30, 2011 by scorch
At the moment there is no official plugin for badges. As the Q2A community isn't very big yet, it probabily doesn't exists any. If you want to share yours, don't be afraid. :)
+14 votes
answered Jul 30, 2011 by NoahY
Okay, here's the plugin:


It now has 6 badges, a basic admin interface (on/off), and a notification system with jquery closing effects.  Place all of the files in the git repository into qa-plugins/badges and navigate to the site.  

This is definitely alpha code!  Not for production sites, yet.
commented Jul 31, 2011 by greg
Thanks very much for sharing the plugin.

I'm sorry but I can't get read.rst opened, so can you please tell me how it works? If you installed it on your site, can you give me the url to see some examples.
commented Jul 31, 2011 by NoahY2
You're welcome... hopefully it will really take off.  The rst file is just a text file.  try "cat README.rst".  If you've put it in the right place, go to the admin-> plugins page to see the badges that are installed.  also, verify that the database tables have been created.  It creates two tables right now, ^badges and ^userbadges (where ^ is the table prefix for q2a).
commented Aug 1, 2011 by NoahY2
Here's the updated info from the github:

The translation file is qa-lang-badges.php.  Copy this file to the qa-lang/<your-language>/ directory.  Edit the right-hand side strings in this file with notepad++ (don't ever use Window's Notepad. For anything. Ever.), for example, changing:

'good_question'=>'Nice Question',


'good_question'=>'Swali nzuri',

for Swahili.  Don't edit the string on the left-hand side or bad things will happen.

Once you've completed the translation, don't forget to set the site language in the admin control panel... to Swahili.
+2 votes
answered Jul 31, 2011 by NoahY2

Okay, the plugin now has 22 badges, but they are pretty simple ones.  Here's the list:

Nice Question - Question received +2 upvote
Good Question - Question received +3 upvote
Great Question - Question received +5 upvote
Nice Answer - Answer received +2 upvote
Good Answer - Answer received +3 upvote
Great Answer - Answer received +5 upvote
Verified Human - Successfully verified email address
Voter - Voted 10 times
Avid Voter - Voted 25 times
Devoted Voter - Voted 50 times
Asker - Asked 10 questions
Questioner - Asked 25 questions
Inquisitor - Asked 50 questions
Answerer - Posted 10 answers
Lecturer - Posted 25 answers
Preacher - Posted 50 answers
Commenter - Posted 10 comments
Commentator - Posted 25 comments
Annotator - Posted 50 comments
Learner - Accepted answers to 1 questions
Student - Accepted answers to 5 questions
Scholar - Accepted answers to 15 questions

also, there is now a Badges page for visitors to see the badge list and descriptions, and the badges now have types (e.g. gold, silver, bronze), with corresponding css coloring.

commented Jul 31, 2011 by greg
Can you please tell me where I can find the texts for Badges? I would like to translate them.
commented Jul 31, 2011 by NoahY2
Great!  They are in the qa-plugin.php file.  Each one is in the following format:

$badges['nice_question'] = array('name'=>'Nice Question','desc'=>'Question received +# upvote', 'var'=>2, 'type'=>0);

I don't quite grock the q2a translation format yet, if someone wants to edit the code to allow it to use the q2a translator, feel free.

Oh, and another thing, I haven't tested all the badges yet, so I don't really know if they work :)  Maybe they just look pretty.  I have tested the nice answer and questions, though... they work.
commented Jul 31, 2011 by NoahY2
Oops... yep.  It's broken... give me a sec.
+1 vote
answered Jul 31, 2011 by WhyCheese

It would perfect if you can set badges and for what you can get them at admin section.

commented Jul 31, 2011 by NoahY2
it's a bit complicated for that... it really takes programming code to work out the logistics of a badge, I think.  What you can do is choose the variables, e.g. how many votes before a question/answer is "nice", etc.
+1 vote
answered Jul 31, 2011 by NoahY2
Okay, I tested out all the badge functions, and they were mostly broken :)  Fixed now.  I am able to trigger all of the 22 badge awarding functions by setting each of the values to 1 in the admin and then carrying out the action.  Try it yourself and let me know.  There is a list of awarded badges in the user profile as well.
commented Jul 31, 2011 by WhyCheese
Nice, thanks again :) Is it possible to manage (delete, add, rename) badges not necessarily at admin section maybe in future... ?
commented Jul 31, 2011 by NoahY2
What I was thinking of was allowing a disable checkbox in the admin for each badge.  As for add/delete, I think it's difficult.  Easier to just add/subtract them in the php code... unless someone wants to expand the project beyond my basic intention.
+2 votes
answered Aug 1, 2011 by NoahY2
Just an update, there is now a translation file, which I assume can be overriden by a language file, but I'm not so sure about that.  The file is qa_lang_badge.php

It is now also possible to disable individual badges and to change the badge names via the admin screen by clicking on the badge's icon.  Descriptions are not editable.

Also, the notification now has a timer, so it fades away automatically after a set (but configurable) time.
+2 votes
answered Aug 1, 2011 by NoahY2
Okay, I think it's almost there.  Let's call this a pre-beta release.  There are now 40 badges in total, what a fairly simple feature set.  Most of the quirky badges will take some time, but I managed to implement a consecutive days visiting badge, so you can keep people coming back :)

The readme is on the github site, again:


and there is a download available there, either in .tar.gz format:


or .zip format:


let me know what you think - I've already contacted Gideon and once the plugin is considered reasonably stable, it may be added to the site.
+1 vote
answered Aug 4, 2011 by NoahY2
edited Aug 4, 2011 by NoahY2
Another update:

There is now a button that (hopefully) allows you to retroactively award badges - it basically runs through all checks for all posts and all users to see if anyone should have been awarded a badge.  I imported 176 questions, 400+ answers and 1000+ comments from askbot, and successfully awarded 600+ badges this way to ~100 users.  The button is on the plugins page badges box.

Also, if anyone has this up and running on a production site, maybe they could share a link so people could see how it works?  I've received a demo request and don't have a demo site to share.
commented Aug 4, 2011 by WhyCheese
No. Now i'm reinstaled plugin to newest version and after rechecking i get error:
"Fatal error: Call to undefined method DateTime::diff() in /xxx/xxx/xxx/xxx/xxxl/xxx/qa-plugin/NoahY-q2a-badges-283c17e/qa-badge-admin.php on line 287"

By the way i don't know how for you but for me new order of badges is not comfortable
commented Jun 15, 2012 by q2apro.com
edited Jun 15, 2012 by q2apro.com
demo from production site: http://www.gute-mathe-fragen.de/badges

However, still using v2.2 of your plugin. Will check your changes now to determine if necessary to update it...

Edit: As far as I see the main change from v2.2 to recent v3.6 is "upgrade lang files to 1.5 way". From checking here: https://github.com/NoahY/q2a-badges/commits/master/
0 votes
answered Aug 6, 2011 by yerbol89kz

Database query error 1048

Column 'object_id' cannot be null

INSERT INTO qa_userbadges (awarded_at, notify, object_id, user_id, badge_slug, id) VALUES (NOW(), 1, NULL, 1, _utf8 'old_timer', 0)


commented Aug 6, 2011 by NoahY
can you update to the latest code and try again?  sorry, it's still under heavy development, but the latest code should fix that error... hopefully :)
0 votes
answered Aug 7, 2011 by Aleams Barra

I had this error message:

Notice: Undefined variable: userid in /home/olimpiad/public_html/ask/qa-plugin/NoahY-q2a-badges-73edc42/qa-plugin.php on line 328

Notice: Undefined variable: userid in /home/olimpiad/public_html/ask/qa-plugin/NoahY-q2a-badges-73edc42/qa-plugin.php on line 328

Notice: Undefined variable: userid in /home/olimpiad/public_html/ask/qa-plugin/NoahY-q2a-badges-73edc42/qa-plugin.php on line 328

Notice: Undefined variable: userid in /home/olimpiad/public_html/ask/qa-plugin/NoahY-q2a-badges-73edc42/qa-plugin.php on line 328

Notice: Undefined variable: userid in /home/olimpiad/public_html/ask/qa-plugin/NoahY-q2a-badges-73edc42/qa-plugin.php on line 328


Also after I checked to activate the badge, all posting (but one) disappear from the front page.

commented Aug 9, 2011 by NoahY
Better to figure this out using private messages...
commented Aug 9, 2011 by Benji
Looks like your last update of qa-badge-layer.php fixed this issue!

Thank you!
+1 vote
answered Aug 18, 2011 by NoahY
Two updates, I figured out what was causing the mysterious qa-page.php errors; Gideon told me not to do something and I kept doing it.  Today I took that code out and the errors finally went away. :)

Also, based on this post:


there is now the option to notify users of new badges via email.
0 votes
answered Aug 25, 2011 by Aleams Barra
Notice: Use of undefined constant QA_FINAL_EXTERNAL_USERS - assumed 'QA_FINAL_EXTERNAL_USERS' in /home/olimpiad/public_html/ask/qa-include/qa-app-format.php(1227) : eval()'d code on line 610 Fatal error: Call to undefined function qa_get_userids_from_public() in /home/olimpiad/public_html/ask/qa-include/qa-app-format.php(1227) : eval()'d code on line 611
commented Aug 25, 2011 by NoahY
It seems, from conversations with Gideon, that QA_FINAL_EXTERNAL_USERS only came into existence in 1.4 (or was it 1.4.1?).  Can you confirm that you are using the latest version of q2a?  If you are, there seems no way you could receive this error, since it is defined in qa-base.php.

I'll update the plugin to specify that it only works with 1.4 and beyond.