Custom Captcha for Contact Form 7

Custom Captcha for Contact From 7 in wordpress is so simple . At present Contact From 7 uses "Really Simple Captcha" plugin to display a Captcha. I will us use the same plugin , But with some minor modifications.

Step 1: Install Contact Form 7 plugin
Step 2: Install Really Simple Captcha plugin
Step 3: We will start with editing Contact Form 7. Open contact-form-7\modules\captcha.php from your Plugins Folder.

Go to line #36  and replace the array with below code.

$op = array(
'img_size' => array( 150, 24 ),
'base' => array( 6, 18 ),
'font_size' => 14,
'font_char_width' => 15 );

If you are using a Multi Site you can control Captcha for specific website using the code shown below.

$current_blog_id = $GLOBALS['blog_id'];
if ($current_blog_id == 120) { // Change your Blog Id
$op = array( // Default
'img_size' => array( 150, 24 ),
'base' => array( 6, 18 ),
'font_size' => 14,
'font_char_width' => 15 );
}else{
$op = array(
'img_size' => array( 72, 24 ),
'base' => array( 6, 18 ),
'font_size' => 14,
'font_char_width' => 15);
}

Step4: Now add the below code into your theme's function.php to disable updates

function filter-plugin_updates ($value){
unset($value ->response['contact-form-7/wp-contact-form-7.php']);
unset($value ->response['really-simple-captcha/really-simple-captcha.php']);
return $value;
}
add_filter('site_transient_update_plugins', 'filter-plugin_updates' );

Step5: Open "really-simple-captcha.php" from Really Simple Captcha Plugin Folder.

Go to line #39 and replace with code below

$this->char_length = 8; // Edit length of Captcha (I am displaying 8 characters)

If you are using a Multi Site use this code
$current_blog_id = $GLOBALS['blog_id'];

if ($current_blog_id == 120) { // Edit your Blog id
$this->char_length = 8;
}else{
$this->char_length = 4;
}

Step6:

Go to line #52 and replace with the code below

$this->img_size = array( 150, 24 ); // height and width of Cpatch image

If you are using a Multi Site use this code

if ($current_blog_id == 120) {
$this->img_size = array( 150, 24 ); // height and width of Cpatch image
}else{
$this->img_size = array( 72, 24 );
}

Step7: Done !!

1 comment:

  1. Thanks for sharing such a informative information with us .GOOD work..
    For more information: http://www.labstech.org/wordpress-captcha-plugin-protect-website-2014-08-24/

    ReplyDelete