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.

<?php $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) : ?>


<?php _e('The captcha code you filled in is correct!'); ?>
<?php endif; ?>

<!-- User Form -->

<form action="" method="post">


<?php _e('Please fill in the code below'); ?>

    <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>


Cleaning Up Really Simple Captcha Plugin Images

To make sure that the directory where the Really Simple Captcha plugin creates it’s images stays clean, see the How to Cleanup Really Simple Captcha Plugin Images article I wrote.