All WordPress plugin developers, you can integrate a security captcha image into your own WordPress plugin using the Really Simple Captcha plugin. It is a plugin in itself but it serves as an API and doesn’t have any purpose on its own without other plugins using it.
This is an example of how to use the Really Simple Captcha plugin API with your own WordPress plugin.
$captcha_correct = false; //set it to false until proven true
require_once(ABSPATH . ‘wp-admin/admin-functions.php’); //include the WordPress admin functions file
if (is_plugin_active(plugin_basename(‘really-simple-captcha/really-simple-captcha.php’))) { //check if the plugin is installed and active
if (class_exists(‘ReallySimpleCaptcha’)) { //check if the Really Simple Captcha class is available
$captcha = new ReallySimpleCaptcha();
if (!empty($_POST)) { //data has been posted by the user, lets check whats going on
if ($captcha -> check($_POST[‘captcha_prefix’], $_POST[‘captcha_code’])) {
$captcha_correct = true; //the captcha has been proven as correct
}
} else {
$captcha_word = $captcha -> generate_random_word(); //generate a random string with letters
$captcha_prefix = mt_rand(); //random number
$captcha_image = $captcha -> generate_image($captcha_prefix, $captcha_word); //generate the image file. it returns the file name
$captcha_file = rtrim(get_bloginfo(‘wpurl’), ‘/’) . ‘/wp-content/plugins/really-simple-captcha/tmp/’ . $captcha_image; //construct the absolute URL of the captcha image
}
}
}
?>
<?php if ($captcha_correct == true) : ?>
<p><?php _e(‘The captcha code you filled in is correct!’); ?>
<?php endif; ?>
<!– User Form –>
<form action="" method="post">
<p><?php _e(‘Please fill in the code below’); ?></p>
<input type="text" name="captcha_code" value="<?php echo esc_attr(stripslashes($_POST['captcha_code'])); ?>" />
<input type="hidden" name="captcha_prefix" value="<?php echo $captcha_prefix; ?>" />
<input type="submit" name="submit" value="<?php _e(‘Submit’); ?>" />
</form>








June 5th, 2010 at 9:53 pm
Using simply captcha designed by Takayuki Miyoshi is a great plugin.It is originally created for Contact Form 7 but you can use it with your own plugin. I believe wordpress die hard fan should try this plugin. I really like the plugin
June 22nd, 2010 at 4:25 am
Thanks for youre posting, i have never heard of it and i will def. integrate this plugin.
best wishes Jan
January 1st, 2011 at 4:47 pm
Thanks for this trick. I use it in my blog and made little customization but it is really helpful.
Thank you very much…
February 20th, 2011 at 7:44 pm
Hello, do you need new module for antispam?
April 7th, 2011 at 11:12 pm
Thanks for youre posting, i have never heard of it and i will def. integrate this plugin.
best wishes Jan
May 19th, 2011 at 7:35 am
Even simpler PHP for wordpress for this:
check($the_prefix, $the_captcha);
if($correct==True)
{
echo “Thats right.”;
// replace the above with whatever you want to do if they typed it right
}
else
{
echo “The Value typed for the captcha is not correct.”;
}
}
$word = $captcha_instance->generate_random_word();
$prefix = mt_rand();
$captcha_instance->generate_image($prefix, $word);
// note change yoururl
$thepic = “http://yoururl/wp-content/plugins/really-simple-captcha/tmp/” . $prefix . “.png”;
echo “”;
echo “”;
echo “”;
echo “Please enter the code.”;
echo “”;
echo “”;
echo “”;
echo “”;
echo “”;
echo “”;
?>
December 13th, 2011 at 12:18 pm
If you use this on a contact page and reload the page it will create *.png and *.php files on each reload.
Anyway to delete those files so it doesn’t fill up the “tmp” folder ?
$captcha_instance->remove($prefix) function can be used on the actual form submit only as it removes the image and code if used anywhere else in the page.
Any ideas ?