XHTML fixes for the WordPress reCAPTCHA plugin

The wp-recaptcha plugin for WordPress breaks when you’re serving pages as application/xhtml+xml. I inadvertently broke comments when I installed it (silly me for not testing!). I’ve written a patch that fixes it.

The default javascript API uses document.write, which isn’t a DOM method and hence is not a method of true XML documents. It’s not a new issue either, wp-recaptcha has had a history of breaking XHTML. The thing is, the WordPress plugin (which uses the PHP library by the recaptcha people) has an option to “Be XHTML 1.0 Strict compliant”; but this only fixes the use of iframes and noscript!

Updated: pushed fork to github

Under firefox, you get an error like:

Error: uncaught exception:
[Exception... "Operation is not supported"  code: "9"
 nsresult: "0x80530009 (NS_ERROR_DOM_NOT_SUPPORTED_ERR)"
 location: "http://www.google.com/recaptcha/api/challenge?k=xxx Line: 12"]

While under Chrome it’s

Uncaught TypeError: Object #<a Document> has no method 'write'
api.recaptcha.net/challengek=xxx

The real solution is to use the reCAPTCHA AJAX API, which for whatever reason isn’t exposed in the PHP library. You can grab my xml fix for wp-recaptcha from github.

Leave a Reply

Your email address will not be published. Required fields are marked *