ngd_recaptcha plugin for TextPattern

If you don’t know what a reCAPTCHA is or the difference from a regular CAPTCHA and want all the details, visit

[…waits while you do that…]

All clear? Great!

This plugin implements reCAPTCHA for TextPattern comments. When a visitor submits a comment they’ll have to solve a reCAPTCHA on the comments preview. If the preview is not solved after the maximum number of attempts, then the comment is sent to the comment moderation queue.


Click here to get your reCAPTCHA keys if you need them.

If you want to use the Mailhide functions, click here to get your reCAPTCHA Mailhide keys if you need them.

Install the plugin and turn it on.

Go to your advanced preferences tab (admin -> preferences -> advanced preferences).
At the bottom you’ll see a section labeled ‘reCAPTCHA’. Fill in the values as follows:

reCAPTCHA for comments enabled [ngd_recaptcha_enabled]
Select yes to enable reCAPTCHA for comments. This allows you to disable reCAPTCHA without taking all the tags out of your code. This does not affect the Mailhide functions.
reCAPTCHA max tries [ngd_recaptcha_max_tries]
Maximum validation attempts. Defaults to 3.
reCAPTCHA failure action [ngd_recaptcha_max_try_action]
Failed comments are sent to the moderation queue. Set to SPAM to additionally mark them as spam.
reCAPTCHA public key [ngd_recaptcha_publickey]
The public key for your site that you got a few steps back.
reCAPTCHA private key [ngd_recaptcha_privatekey]
Ditto, but strike public, insert private.
reCAPTCHA Mailhide public key [ngd_recaptcha_mailhide_publickey]
The reCAPTCHA Mailhide public key. Only needed if want to you want to use the Mailhide functions.
reCAPTCHA Mailhide private key [ngd_recaptcha_mailhide_privatekey]
Ditto, but strike public, insert private.
Display reCAPTCHA debug messages [ngd_recaptcha_debug]
Turn this off for production sites, but if you are having issues, this will print out a debug message where the reCAPTCHA image or Mailhide should show (missing lib, keys, etc). Note: Incorrect keys will cause an error to display regardless of these settings. If anyone reallllly has a problem with that, let me know (not promising to do anything about it tho).
reCAPTCHA tabindex [ngd_recaptcha_tabindex] (v1.1)
Adds a tabindex to the input field, for accessibility goodness

reCAPTCHA lang [ngd_recaptcha_lang] (v1.1)
Set the language for your reCAPTCHA. As of this writing, supported languages are: English, Dutch, French, German, Portuguese, Russian, Spanish, Turkish.
If you need another language you can use custom theming to accomplish that.

reCAPTCHA theme [red | white | blackglass | clean | custom] (v1.1)
The reCAPTCHA theme you would like to use. Defaults to red.

I think they are pretty self-explanatory- red is red, white is white, blackglass is purple with cow images black/grey. The clean theme is transparent. – (btw gTxt turns ‘clean’ into \clean\ at least on my install – I know but want it translatable, so it’s not a bug).
See details on custom theming below.
reCAPTCHA custom theme widget ID [ngd_recaptcha_custom_theme_widget] (v1.1)
A unique DOM id used for display of the widget. Used in conjunction with custom theming (see below)

Save your preferences and test it out. If it doesn’t work, try turning the debug option on. If you still cannot get it to work, disable it and report the problems.

That’s it! Enjoy your newfound security and the warm fuzzy that comes with helping a good cause.

Mailhide function

You can find out more about the reCAPTCHA Mailhide here.

Usage: <txp:ngd_recaptcha_mailhide></txp:ngd_recaptcha_mailhide>


0: returns the url only.
1: returns a link (default).
You can also pass the privatekey along here if you prefer.
You can also pass the publickey along here if you prefer.

Custom Theming (v1.1+)

If you don’t like the standard themes, you can now use reCAPTCHA’s custom theme settings to style the display to your site.

Important: If you use a custom theme you must declare a custom theme widget id and call <txp:ngd_recaptcha_get_html /> after that element in your comment.

Details are available on the reCAPTCHA site, so I won’t go into them here, but here’s the basic form you would put into your comment template:

<div id="recaptcha_tag" style="display:none;">
<div id="recaptcha_image"></div>
<p class="recaptcha_only_if_incorrect_sol" style="color:red"><txp:text item="Incorrect please try again" /></p>
<span class="recaptcha_only_if_image"><txp:text item="Enter the words above:" /></span>
<span class="recaptcha_only_if_audio"><txp:text item="Enter the numbers you hear:" /></span>
<input type="text" id="recaptcha_response_field" name="recaptcha_response_field" />
<br />
<span><a href="javascript:Recaptcha.reload()"><txp:text item="Get another CAPTCHA" /></a> &bull; </span>
<span class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type('audio')"><txp:text item="Get an audio CAPTCHA" /></a> &bull; </span>
<span class="recaptcha_only_if_audio"><a href="javascript:Recaptcha.switch_type('image')"><txp:text item="Get an image CAPTCHA" /></a> &bull; </span>
<span><a href="javascript:Recaptcha.showhelp()"><txp:text item="Help" /></a></span>
<txp:ngd_recaptcha_get_html />


The only known issue is if you want to totally uninstall the plugin. This plugin adds some records to your txp_prefs table. If you don’t care if they stay there and you still see the reCAPTCHA settings in your preferences, do nothing. Otherwise, use PHPMyAdmin or the Textpattern db_manager plugin or whatever other program you like and run this query: DELETE FROM txp_prefs WHERE name LIKE ‘ngd_recaptcha_%’ (you may need to add your table prefix if you use one). If that sentence made no sense to you, I suggest you just live with the change rather than attempt something you aren’t familiar with-leaving the records does no harm.


I used the asy_captcha plugin by Sencer Yurdagul as a model.


1 Morgan Aldridge - Jan 17, 01:31 PM

I’ll have to give this a try!

I’ve been working on/using my own reCAPTCHA plug-in for Textpattern since somewhere around December of 2006. I had planned to do an initial release in July of 2007, but Manfre posted a reCAPTCHA plug-in then so I held off and just kept using mine.

Two weekends ago I talked to Manfre on IRC and tweaked mine to release, but hadn’t gotten a chance to provide documentation, so held off releasing again. So now, as things seem to go with my reCAPTCHA plug-in, all my effort was for naught… you’ve released yours!

Actually, it was a very good for the expansion of my Textpattern plug-in development skills, but I must be jinxed!

How actively are you looking and supporting yours? I may send you some code & fixes to merge bits of my functionality in if you like or don’t mind.

2 Sara Jacobson - Jan 18, 08:44 PM


Thank you. This is my first ‘official’ contribution to TextPattern (about time since I’ve been using it for two years now!). I’ve many others ‘in the works’ but this is the first I’ve managed to finish and publish.

I didn’t see Manfre’s until after I’d almost finished it, and since they do different things figured it would still be a worthwhile effort to continue.

I think it is pretty stable but there is always room for improvement. Right now it only activates on comments-if there’s a need I’ll flesh it out more.

Given my track history I’d welcome any collaboration on your part. There’s a wonderful plugin diff contribution that is very helpful if you find things to improve upon.


3 chris - Jun 11, 02:31 AM

Hi – i’m struggling to implement this.

When I fill in the words and hit enter, do I also need to hit Submit on my comment or not? Also, how can I position the Recaptcha widget within my sites structure?

4 Sara Jacobson - Jun 11, 08:50 AM

It’s been a while so I test in the easiest manner – by adding a comment. :0

5 Sara Jacobson - Jun 11, 09:21 AM

Mkay- the answer is…mixed.

I just hit the [enter] key directly after typing. Doing either should submit the form (which is all you are doing). There may be some variance browser to browser (Safari may require you to hit ‘submit’) but so long as your comment preview form is standard (‘submit’ being the default action rather than cancel or otherelse) it should work in both cases.

As to the position-it’s appended to the end of the form automagically. The id for the primary container div is “recaptcha_widget_div” – you could use some CSS magic to apply some styling. There are a couple other id’s too (just view the source to see them).

Please clarify if I’m misunderstanding.

6 Locum tenes job - Jun 15, 10:53 PM

So is it better than the regular? i wanted to switch to the RedCaptcha also

7 Sara Jacobson - Jun 15, 11:57 PM

Better? Well, the function is the same as a regular captcha, and effectiveness likely the same as well. However the recaptcha uses 2 real words, which are easier to type than the nonsense strings generated by normal captchas, plus there’s the altruistic hook of helping to digitize books.

8 Jen - Aug 19, 07:41 AM

Very nice! Exactly what I needed, and worked like a charm.

9 moontan - Sep 8, 09:39 AM

Very smooth indeed. There’s just one thing I’d like to complain about: I cannot customise the position of the reCAPTCHA box. The plugin places it right after the
txpCommentInputMessage class text area which sort of disfigures my layout. Would it be possible to introduce a customisable txp tag here, just like asy_captcha did?

10 Sara Jacobson - Sep 12, 08:12 PM

let me see what i can do

11 Sara Jacobson - Sep 12, 11:43 PM

Okay, I’ve added theming abilities so you can customize things a bit. It may be a bit different than what you expect but I’m working with an outside API.
Try out version 1.1 and let me know what you think before I publish to Txp Resources.

12 Molly - Nov 6, 04:59 AM

Hi Sara—

Thanks for your recaptcha plugin. I have been using it for a few months, and it’s great!

There’s one annoying little #$@! who posts a comment every night on my site, apparently attempting to advertise his site. He’s a human, not a robot, so he passes the recaptcha. I have sent e-mails asking him to stop, but he keeps on posting it. I have tried blocking the IP, but every night it’s a little different.

I am trying to use two other anti-spam plugins to block his URL, but it doesn’t seem to work. Does the recaptcha plugin bypass a process that triggers these other anti spam plugins?

The plugins are mrw_spamkeywords_urlcount and nko_spamurl_blocker.

13 Sara Jacobson - Nov 8, 08:10 AM

I’ll check it out.

14 Sara Jacobson - Nov 8, 12:41 PM

okay. came across another error i am trying to debug but you can change the ‘weight’ on the spam plugin you use to higher than 0.75 on the evaluator and it’ll outweigh the recaptcha one. it’s set at 0.6 now

I’m still checking on another issue (gotta see if I can recreate it)

15 Molly - Nov 11, 07:06 AM

Thank you, Sara. :)