Version 3.1.4 of Peter’s Math Anti-Spam for WordPress

Here’s another spin-off of Peter’s Custom Anti-Spam Image for WordPress that will generate math anti-spam equations as images instead of custom anti-spam images.

I’ll repeat what I wrote in the original post: there are quite a few plugins to combat blog comment spam, and they usually come in two varieties: one that filters and identifies spam posts and another that forces users to identify a random word displayed as an image in order to block spambots that cannot read your image. You can (and should) use both varieties of spam filters in tandem. Spambots are getting smarter and some can read images. Most, however cannot.

The goal of this spin-off plugin is to further fool spambots somewhat by combining the “make them answer a math equation” and “make them read an image” ideas. This plugin aims to keep the readability of the Custom Anti-Spam version, as well as other features like random fonts and colours.

Screenshot of the math anti-spam image

Without further ado…

Version 3.1.4 of Peter’s Math Anti-Spam Image Plugin for WordPress [August 2, 2010: Minor code tweak for WordPress 3.0.]

English release



For version 3.1.3 and up, extract these files over an existing English plugin install:

Older versions:

For details on the changes from version 3.1.3 and higher, read the history page for the custom anti-spam plugin.

Version 1.0.5 [August 2, 2008: Added a setting $cas_wpconfig for the absolute path to wp-config.php for WordPress 2.6+ users who have moved either wp-config.php or the wp-content folder from the default locations.]

Version 1.0.4 [May 31, 2008: Fixed the registration form protection for WordPress 2.5. Pre-WordPress 2.5 users who want to use the registration form protection must use Version 1.0.3 of this plugin or lower.]

Version 1.0.3 [May 24th, 2008: For efficiency reasons, image and audio generation is now run directly through the plugin file.]

Version 1.0.2 [March 13th, 2008: Minor tweak to ensure compatibility with WordPress 2.5.]

Version 1.0.1 [February 10th, 2008: New option to disable random stretching of the wav files. Made the operation to stretch the wav files silent to the server(thanks Angelo!). Blocked indexing of audio file links by search engines (thanks Lucky!).]

Version 1.0.0 [January 20th, 2007: Added registration form protection (WordPress 2.1 and higher required) and a corresponding e-mail blacklist. For registration form protection, set $cas_reg_protection equal to "true". Also tweaked the audio file generation with wav files to be more robust against spambots.]

Version 0.1.6 [November 20th, 2007: Minor code tweak to the image and audio generation code so that full page generation doesn't occur unnecessarily (thanks Steve!).]

Version 0.1.5 [November 11th, 2007: Made a few minor efficiency and display tweaks, and switched up the fonts.]

Version 0.1.4 [October 13th, 2007: Tweaked a database command to be more compatible, allowed a site address override (over the WordPress site URL value), and removed some redundant code.]

Version 0.1.3 [September 30th, 2007: Fixed a bug that was blocking trackbacks and pingbacks for the past few versions (a stupid oversight on my part in the order of some code).]

Version 0.1.2 [September 26th, 2007: Fixed minor CSS detail, allowed for different folder names for the plugin, and renamed mp3 class to avoid the possibility of clashes with other class names.]

Version 0.1.1 [September 10th, 2007: Fixed a bug whereby the audio files weren't generating in all Internet Explorer setups. Fixed a bug with the "don't force registered users to enter the anti-spam word" setting. Changed table creation method so that PHP installations with low memory allocated to scripts will still be able to create the necessary tables. Also, made all display strings more easily customizable, to enhance translation support.]

Version 0.1.0 [September 3rd, 2007: First version!]

Unzip the entire folder math-anti-spam to your plugins directory, so that the path is wp-content/plugins/math-anti-spam/. Then activate the plugin via your WordPress admin section. The plugin should work directly “out of the box”. For version 3.1.3 and higher, all settings can be customized in the Settings > Math anti-spam page in your WordPress control panel. For versions 1.0.5 and lower, all instructions for customization are found by editing the plugin file (in your WordPress control panel, go to Plugins > Edit Plugins).

Forum for Peter’s Math Anti-Spam Image

Forum/Topic Started Last post Posts

Note: this blog uses the Custom Anti-Spam version of this plugin. To see the Math Anti-Spam version of this plugin in action, check out


54 Responses to “Version 3.1.4 of Peter’s Math Anti-Spam for WordPress”

  1. Rui Cruz says:


    Are you willing to upload a Portuguese pack or other languages pack about your script?
    Or share a link?

    I’m today working on translating the MP3 files and would be great to share it with others.

    Great plugin. I was a long time searching for someting with acessibility in mind.


  2. WirelessGuru says:

    Thanks for taking my suggestions and making it a working plugin. Gonna wait until WP 2.3 rolls out to try it. Keep up with the useful crap!

  3. Peter says:


    Yes, I am definitely willing if you create and e-mail them to me :D

    I’ll post it and give you credit via a link back or mentioning your name!

    Thanks a lot!


    Thanks for the comment! I credited you in the plugin file itself… after all, this plugin would never been made if not for your idea.

  4. Plugins WordPress – Ajuda os teus leitores a comunicarem nos comentários do blog says:

    [...] para a frente já podem comentar melhor Há muito mais tempo atrás também instalei o plugin anti-spam. Este plugin “obriga” a que insiram o valor da soma de dois números para o comentário [...]

  5. WirelessGuru says:

    I upgraded to WP 2.3 and switched to your Math Anti-Spam plugin. Works great! Thanks for your great anti-spam solutions, and continued support of them.

  6. george says:

    hi Peter!
    the math anti spam works fine if I have the wordpress index.php and the rest of the files and folders in ONE folder. but wordpress gives the opportunity to place index.php in a different place out of this folder. but in this case math anti spam won’t work no matter how I try to define paths in the main plugin file.
    what can I do, where goes the code wrong?
    thanx for your reply!

  7. Peter says:

    Hi George,

    Try experimenting by changing this setting — $cas_siteurl = "http://yoursiteaddress/whatever"; — to be:

    1) The URL to the original index.php location
    2) The URL to your new index.php location

    If this doesn’t work, can you tell me where you site is so that I can check it out?

  8. WordPress Plugins – Help your readers communicate better with comments says:

    [...] had also installed the anti-spam plugin some time ago. With this plugin you have to add two numbers and put in the correct total before [...]

  9. steveegg says:

    Question; is the math anti-spam essentially on the same development track as the custom anti-spam (i.e. MAS 0.1.4 having the same code base as CAS 2.9.5)? If so, I plan on switching to the math plug-in as some bots are starting to become bright enough to make it through 2.9.5 (more at that forum).

  10. Peter says:

    Yes, this one and the random anti-spam version are developed together with the custom anti-spam version. Lately, when I release updates, I release the same updates at the same time to all three versions.

    Ironic that you ask this, because I responded to your question in the forum before reading this comment… and I suggested that you switch to the math anti-spam and rotate the plugin once in a while :D

  11. » Blog Archive » back atcha, captcha! says:

    [...] from Shamus and installed a captcha plugin. I’m using a derivative of the one he uses, called Peter’s Math Anti-Spam Plugin, and again taking a cue from Shamus I’ve configured it so it shows exactly the same math [...]

  12. Aziz says:

    Hi there,

    I just installed the plugin and am extremely happy. Is this the right venue to make a feature request? I would love to see the same captcha engine used on the registration page.

    Bots and spammers can of course bypass the captcha on teh comment form if they register for an account (and for various reasons, you might not want to close registration down). So, the same captcha would be ideal.

    As a secondary feature, for the registration, if you could allow an optional blacklist to be specified as well for email addresses, that would really consolidate all the best frontline defense methods into one package.

    Again thank you for such a wonderful plugin. I hope you have time/inclination to extend it as I’ve requested because I’d much rather stick with your code than find additional plugins to do the job.

  13. Peter says:

    You could actually just force registered users to enter the anti-spam answer with the $cas_forcereg setting, but I can see how registration form protection would come in handy.

    Here’s a beta version with registration form support:

    It works on my test installation — let me know how it goes on your site.

    The blacklist settings for the registration form are at the bottom of the usual settings.

  14. Explosivo says:

    Hi! Your plugin in my wordpress isns’t working.. I think is the template, you don’t have any possibility to this plugin works in my template? My template is FreshBlue Idea 1.5. My blog is


  15. Peter says:

    If the anti-spam field does not display at all, make sure you have logged out first, because by default it does not display to registered users (although you can change that with the $cas_forcereg setting). Failing that, try the manual insert method (as described for the custom anti-spam version).

    If it displays a broken image, check that you have the necessary libraries installed (FreeType and GD Library).

  16. Lemmy says:

    Hi… I’ve installed your custom anti spam plugin as a friend of mine uses it and it works great. Bizarrely it doesn’t display the word in the box when someone tries to leave a comment. Any ideas on what I need to do?

  17. Peter says:

    If you look at the source code for your page, there’s some extra <head> tag and other information that is unnecessarily duplicated and thus is conflicting with the plugin.

    The problem has something to do with this: “META Tags generated by”

    I suspect that there’s some erroneous settings there that makes whatever it generates get submitted twice.

  18. Peter says:

    Hi, one of the settings in the plugin file addresses that:

    // Set this to equal TRUE if you want to force registered users to enter the anti-spam word as well.
    $cas_forcereg = true;

  19. Tololy says:

    Hi, I have just installed your plugin on my blog and it works great. I have a question though, the audio files pop up in a different window with an option to save them. Is there a way to make them play in the same page, i.e. be embedded in the page? That would make life so much easier.

    I am not sure if you still receiving suggestions and comments here, but I just had to share. Thanks for a wonderful plugin!

  20. Peter says:

    Hi, that is actually a feature of the user's setup. For example, my browser is configured to play .wav files in Quicktime embedded in the browser. If I didn't have Quicktime installed and configured as such, when I click on a link to play the .wav, the browser will pop up a download link. One thing that I could do with the plugin is to use a Flash player to play the audio file on the page itself, but then that relies on users having Flash installed. So I figured that the best way to make the audio file accessible to as many people as possible is to simply let the user's setup decide how to handle the .wav file (although I am open to suggestions for a better way).

  21. Tololy says:

    Thanks for responding Peter. That was super quick! I am not a very techie person but maybe some readers on my blog will suggest ways for audio playback.

  22. Classics says:

    Hi ! And congratulations for this wonderful plugin.
    I've just installed the 1.02 version and i have a problem : how can i change the color of the image ? I'd like a black background. It was easy to change that with the previous version but impossible to find with this one.

    Thanks for help. :-)

  23. Peter says:

    Hi Classics — you can change the background colour with this setting:

    $cas_bgcolorset = "black";

  24. Chris Masse says:

    Hi, thanks for this great plugin. I have iton my 3 blogs. On on of them, the tables "wp_mas_eqcount" and "wp_mas_equations" have disappeared and no way I can reinstate them by deactivating and reactivating the plugin… Mystery….
    Have you got an idea?
    Chris Masse

  25. Chris Masse says:

    Solved. I have updated to version 1.0.2…
    Thanks a lot…
    Chris Masse

  26. Don says:

    I’ve tried to use the Absolute Comments plugin by ozh which allows one to answer comments from within the admin area. A great idea.

    However, the math anti-spam, also a great idea, asks for the captcha from the person logged into admin. Thus, ozh’s plugin can’t process due to the fact that his comment form doesn’t include your captcha. It seems kind of overkill to require the admin to enter the captcha unless I’m missing something. I realize of course it’s probably an oversight since previously we weren’t able to answer comments from inside admin anyway. No reason to worry about such a problem.

    So, is there a way to disable the captcha for the admin? Or come to think of it, any user who is logged in?

    Can you point me in the right direction to hack it?


  27. Don says:

    I found the option for allowing registered users. Sorry!
    That fixed it.

  28. Chris Masse says:

    Hi, Thanks for this great plugin.
    When WP Spam Free is activated, the image from your plugin showing the math equation does not appear. I’ll also tell the WP Spam Free plugin author. I have the latest version of WP 2.5 and of these two plugins.
    Here’s the list of my plugins:

  29. Chris Masse says:

    I forgot to say "thank you".
    Chris Masse

  30. Peter says:

    Hi Chris,

    Have you tried trying each plugin individually to see if one of them is broken on their own? I just ran a test installation with both plugins installed and it worked.

    Perhaps it is just a problem with my plugin or with the WP Spam Free plugin. Clues on problems with my plugin can be found in the Manage -> Math anti-spam page in your WordPress admin panel.

  31. Chris Masse says:

    1. have just disactivated WP Spam Free and have activated Vad Behavior instead. And all is fine since then. So the culprit is the interaction between WP Spam Free and Peter’s Math Anti-Spam Image Plugin.
    2. Yes, I know of this page. I have frequently watched it, and it has always been saying that all was / is fine.
    Chris Masse

  32. Chris Masse says:

    Spot the answer from the other plugin author.

  33. WirelessGuru says:


    Sometime after WP 2.5 the Math Anti-Spam and Custom Anti-Spam stopped displaying the graphic on my website

    In testing I’ve reverted back to older versions of the plugin, disabled all other plugins, tried it using 3 different browsers on 2 different computers, etc. Today I just upgraded WP from 2.5.1 to 2.6.1 thinking that might fix the problem – it did not.

    I’ve left the plugin activated temporarily so that you can check out my site should you choose.

    Any suggestions? Thank you.

  34. Peter says:

    Hi, WirelessGuru, sorry to hear about this. Based on a previous report of a similar problem (image loading just hangs) I suspect this might be an issue with the compilation of either the FreeType or GD libraries and not with upgrading WordPress. Try contacting your web host and get them to re-compile PHP with those libraries. Those libraries might already be installed, but something might have simply messed up.

  35. WirelessGuru says:

    Peter, I contacted my host with the information you suggested – and the problem is fixed. They replied with:

    "I have made PHP5 as default version of php for [your] domain
    Now I could see [your web page] is loading fast and fine from our end. Please be informed that PHP is already complied with GD libraries on the server."

    I’m don’t know much about PHP, but I assume from their response that they upgraded me from an older version – and that must have fixed the problem.

    Thanks for your help. Keep up the good work.

  36. Pedro says:

    Hello Peter, and thanks a lot for this plugin. I used to use verion 0.1.1 with WP 2.2.x, and it worked very nicely.

    Now I have upgraded my WP to 2.6.1, and I am using your plugin version 1.0.5, and it is not working, in the sense that spam is getting through. I have confirmed that it works because I need to enter the right sum value to have a comment posted, but somehow spam bots are getting through. I know they get more and more intelligent.
    However, the fact that spam started to come in when I upgraded both WP and this plugin, makes me think that either I installed something incorrectly, or there’s a hole somewhere when using this plugin with WP 2.6.1 (or with the other plugins active in my site: "Subscribe To Comments" and "Bookmarkify").

    I am still trying to debug the problem… but any ideas or suggestions are welcome. Thanks!

  37. Peter says:

    Hi Pedro, sorry to hear about your problems. Please see this thread, with some discussions about possible reasons for the spam. Even though it’s centered around the custom anti-spam version, all of the discussion points are relevant.

  38. Pedro says:

    Hello Peter, hello all:

    I found the root of the problem I was having: spam is coming in through tracebacks, because I didn’t block tracebacks in the math anti spam plugin.
    However, I hadn’t blocked them either in the old version that I used to use.

    It turns out that I had been using version 0.1.1. Then, I see that in v0.1.3 a bug was fixed that had been blocking pingbacks and tracebacks irrespective of the configuration settings. I guess that’s why I received no spam through tracebacks with v0.1.1.

    Now, in 1.0.5 I have to block tracebacks explicitly to mimic the behaviour of v0.1.1.

    Thanks again, Peter, for this anti-spam plugin. Cheers!

  39. Stefan says:

    Dammit! Since yesterday spam robots are flooding my blog. Seems that they finally hacked Peter’s Math Anti-Spam.

  40. Stefan says:

    Sorry, my fault: My Blog was flooded by pingback spam.

  41. DewDrop says:

    Hi, I’ve been using the anti-spam for comments for a long time now and really like it. But I got a notice today that the plugin I’ve been using for a contact form, Cforms, is no longer supported for WP contact forms. Is there any plan to make a contact form version of math ant-spam? I’m thinking they could share images and audio files, and just have different functions.

  42. Peter says:

    Hi DewDrop. I don’t have any immediate plans to expand it to contact form functionality. However, if there are any developers that want to borrow the anti-spam code, please feel free to do so :D

  43. DewDrop says:

    Rats. I only know how to make themes.

    But how hard can plugins be anyway? (Maybe if I wait long enough someone will beat me to it.)

    Thanks anyway, Peter. :-)

  44. Bill says:

    Dear Peter

    I have had 1.0.2 working fine. I recently upgraded to 3.1.3 using WP3.7 and for a while this worked fine also. Today the images no longer want to display. I checked the compilation of the FreeType and GD libraries (especially the latter) no problem using PHP 5.1.6 also.

    What could have happened?

    I have reverted back to 1.0.2 for now and that is displaying fine.

    thanks for all your great work.

  45. Bill says:

    To follow up I also installed the custom 3.1.3 plugin – no luck either. A further clue is that the I clicked on the image that doesn’t display to hear the sound and I got a single line message in the browser saying – "Some data has already been output, can’t send wav file" – I cannot find this message in custom_anti_spam.php so it is coming from the browser ….

    Does this help you solve the problem?

    best wishes

  46. Peter says:

    Hi Bill, my suggestions are to check that you have ported over any settings from before and also to make sure that the plugin has the correct path to the wp-config.php file (look for the $cas_wpconfig file in the plugin itself) — if you have moved wp-config.php or the wp-content folder from their normal locations. Since the image generation scripting has remained largely the same and you say the previous version works, I can’t think of any other obvious causes.

  47. Riin says:

    Hi Peter. I’m using the math anti spam plugin for my comments, and I’m wondering if there’s a way to also use it in a contact form. Is there some code I can paste into the form to make it use your plugin?


    Reply from Peter: Because contact form plugins do not hook into the WordPress comment system, at the moment there is no quick way to integrate my anti-spam code with them, although it’s certainly do-able. However, the exact way to do it would vary across contact form plugins. One quick and easy way to do this is to just use one normal page as a contact form — suppressing the display of comments posted to that page but still using the comments system.

  48. Riin says:

    Ooh, sneaky. I like it! Can you tell me how to suppress the display of comments to just one page? I don’t see an option for it, or do I need to enter something (?) into the custom fields?


    Reply from Peter: Again, it varies, this time based on the theme. Usually, you can add an “if” statement around the output of comments in your comments.php template. On some templates, there will be some code such as if ($comments) which you can then edit to say if( $comments && 21 != $post->ID ) where “21” is the ID of your comment page. For a good user experience, you should then give the user a thank you page or message after they’ve submitted their message. Check this post for an outline on that.

  49. Sham says:

    I was using your captcha plugin long since.It was working great.But off late i am facing a problem.Suddenly the captcha image is not loading at all its telling **Invalid** .Do help me out..

    Here is the screenshot:

    Reply from Peter: Did you recently add a caching plugin? If so, set the option “Use JavaScript to generate anti-spam code” to “Yes”.

  50. Rita NM says:

    Hi Peter. I’m using the math anti spam plugin for my contact form.. so far no spam on my inbox.

  51. Gail from GrowMap says:

    I have been getting intermittent complaints that the Math plugin has been intermittently failing and today I saw it myself. I have 3.1.3 installed.

    Instead of a math equation ***INVALID*** is displayed. Is there a fix? Is this the latest version? (There is no indication there is a newer one.)

  52. Gail from GrowMap says:

    I believe the issue I’m seeing may be related to a conflict with the Hyper Cache plugin (based on a comment and your reply on this page). You said, "Reply from Peter: Did you recently add a caching plugin? If so, set the option “Use JavaScript to generate anti-spam code” to “Yes”."

    Where is that option? In the Math plugin or the Caching plugin? I don’t see any options for the math plugin and nothing similar to that in the caching plugin.

    Reply from Peter: In the WordPress admin interface, you should see Tools > Math anti-spam.

  53. Øyvind Granberg says:

    Can you tell me how I can change the text on the "Submit Comment"-button?
    I am trying to norwegianfy your excellent plugin.
    I like useful "no frill" solutions…

    Reply from Peter: That text is probably found in your theme’s comment and/or post templates. It’s not in this plugin’s files.

  54. Dave Hodges says:

    A system like this works well. I had a comment where the anti spam question was "3+3".
    The commenter must have used a service because the anser typed in was "3+3"

    However, I’ve noticed all too often that many sites have taken this to extremes, and the captchas are entirely unreadable – whether human or not – there is not much further the route of a plain text response can go – the method needs a twist.