Divi WordPress Them — the smartest and most flexible WordPress theme

Back to Top

Better WordPress reCAPTCHA (support Akismet and Contact Form 7)

Better WordPress reCAPTCHA (support Akismet and Contact Form 7)

This plugin utilizes the popular anti-spam library, reCAPTCHA, to help your blog stay clear of spams. This plugin can also integrate with Akismet.

In the 21th century, spamming could be one of the most annoying problems for a website. Especially if you use some publishing platforms like WordPress, your blog WILL be spammed and no default methods will save you from such nightmare.

BWP reCAPTCHA utilizes the popular anti-spam library, Google reCAPTCHA, to help your blog stay clear of spams.

Plugin Features

  • You can add captcha to comment form, user registration form, site registration form and login form
  • You can add captcha to form generated by Contact Form 7 plugin
  • Hide captcha for qualified visitors
  • Comment Form:
    • You can position captcha before or after the comment field
    • Control how the plugin reacts when captcha response is invalid
    • Set error message when captcha response is invalid
  • Theme Features:
    • reCAPTCHA version 2:
      • Choose between 2 default themes
      • Normal or compact size
      • More than 50 languages
    • reCAPTCHA version 1:
      • Choose between 4 default themes or create your own (sample CSS and images provided)
      • Use built-in languages or add custom translations
  • Integrate with Akismet for better end-users experience, i.e. “only force a CAPTCHA when a comment looks like spam”.
  • WordPress Multi-site compatible: you can set different key pair for each site or use a single key pair for all sites.
  • And more…

Plugin Usage

reCAPTCHA versions

As of version 2.0.0, BWP reCAPTCHA will make use of reCAPTCHA version 2 by default. This allows you to utilize the no captcha reCAPTCHA.

You can read more about reCAPTCHA version 2 here.

If for some reasons you prefer to use reCAPTCHA version 1, just go to BWP reCAPT > General Options and select “Use reCAPTCHA version 1”.

Please keep in mind that you can not have multiple captcha instances on one page with version 1, so upgrading to version 2 is highly recommended.

Add reCAPTCHA to comment form

Depending on your theme, there are two ways you can add captcha to your comment form.

Themes that use comment_form() function

The comment_form() function1 that comes with WordPress 3.0.0 is a neat function that outputs a comment form for a theme hassle-free. If you have updated to WordPress 3.0.0, you should see this function in action in Twenty Ten theme’s comments.php.

For themes that use this function, you do not have to do anything, after plugin activation captcha will be shown whenever possible.

As of 1.1.1, captcha is added to just below the comment textarea field. You can select a different position by navigating to BWP reCAPT > General Options > reCAPTCHA for comment form and then choose to display captcha after author fields instead (name, email, website).

Note: If you’re using WordPress 4.1 or older, and you add custom comment_notes_after argument to comment_form() function AND want to display captcha below comment textarea field, you will have to use this instead in comments.php:

if (function_exists('bwp_capt_comment_form')) {
   bwp_capt_comment_form(array('comment_notes_after' => 'my_custom_comment_notes'));
}

bwp_capt_comment_form() accepts the same arguments that comment_form() would accept, namely $args and $post_id.

Themes that do not use comment_form() function

Although this might seem a little more work for you, it is actually better. You are given more freedom to create your comment form, instead of relying on a whole bunch of filters and such.

All you have to do is to add this line: <?php do_action('bwp_recaptcha_add_markups'); ?> to comments.php, at the position where you want the CAPTCHA to appear. You should position it at least before the submit button, otherwise it wouldn’t make any sense.

Note that you should position the above line outside of any if tag that checks if the user is logged in, this is to ensure the CAPTCHA will be shown even for registered users. Simply put, just put it right before or right after the comment textarea and you are fine.

Add reCAPTCHA to other WordPress forms

reCAPTCHA can also be added to other forms, including:

  • WordPress Login Form
  • User Registration Form
  • User/Blog Registration Form (Multi-site installation)

Please note that the captcha is NOT added to the above forms by default. Go to BWP reCAPT > General Options to enable it for appropriate forms.

Hide reCAPTCHA for qualified users

You can hide the captcha for the following users:

  • Registered Users (even with no capabilities needed)
  • Authorized Users (users who have some capabilities, and you can extend the default list)
  • Visitors who have at least a required number of approved comments

Since version 2.0.0 of this plugin, the captcha will be visible to all users by default, and you must explicitly choose which users you want to hide the captcha for.

Customization

Custom Capabilities

If you choose to hide reCAPTCHA for authorized visitors, you must choose which capabilities are allowed to bypass reCAPTCHA. By default you can choose between users who can Read profile (subscriber) or users who can Manage Options (admin).

To extend those capabilities, use something like this:

add_filter('bwp_capt_bypass_caps', 'bwp_add_custom_caps');

function bwp_add_custom_caps()
{
    $custom_caps = array(
        'Capability title' => 'capability'
    );
    return $custom_caps;
}

Capability title can be anything you see fit, but capability should be identical to capabilities provided by WordPress. You can find a list of capabilities here: Roles and Capabilities.

reCAPTCHA version 2

You can customize certain aspects of the captcha widget version 2, as shown below:

http://betterwp.net/docs/html/_images/bwp-recaptcha-v2-theme-options-thumb.png

reCAPTCHA Version 2 Customization

It is not possible to have custom HTML markups or custom styling like version 1, unfortunately.

reCAPTCHA version 1

Custom styling

This plugin comes with 4 default themes provided by reCAPTCHA and a custom theme you can customize. By default, the custom theme will look like this:

http://betterwp.net/docs/html/_images/bwp-recaptcha-demo-thumb.png

Custom Theme Demo

If you don’t like such design, you can change its look by disabling the CSS provided by this plugin in BWP reCAPT > Theme Options > uncheck “Use default CSS” and then enqueue your own CSS in theme’s functions.php. For example:

wp_enqueue_style('bwp-capt', 'url-to-your-css');

Or if you prefer, you can leave the setting untouched but replace the default CSS with a filter, for e.g.:

add_filter('bwp_capt_css', 'my_capt_css');
function my_capt_css($default_css_url)
{
    return 'url-to-your-css';
}

Note the $theme variable added as a parameter for the callback function, it lets you know what theme you are using, allowing to style catpcha components correctly for each theme. For example the “clean” theme is very wide so your wrapper should probably be styled wider, too. Possible values of the $theme variable are ‘clean’, ‘red’, ‘white’, ‘blackglass’, and ‘custom’.

Custom HTML markups

Add bwp_capt_custom_theme_widget() function to your theme’s functions.php to override the default HTML markups when using Custom Theme. Check out reCAPTCHA’s official documentation (section Custom Theming) to know how to properly set up custom markups.

Take this a bit further, you can change the theme property of RecaptchaOptions object to any default theme, and then add any other necessary markups if you need. I’d call this Customized Default Theme.

Custom translations

By default, this plugin only provides 9 languages but you have the option to add custom translations. You can use custom languages for both default themes and custom theme, refer to this dedicated tip for more details.

Contact Form 7 Integration

As of BWP reCAPTCHA 1.1.0, you can add a BWP reCAPTCHA tag to any Contact Form 7’s forms easily without the need of an integration plugin.

Please refer to this dedicated how-to for more details.

Akismet Integration

One of the feature that distinguishes this plugin is the ability to integrate with Akismet, i.e. only show reCAPTCHA when the user has posted something considered spam by Akismet.

I try to design this plugin in a way that considered spam comments would never be added to the database unless the user successfully completes the captcha. The benefit is you don’t have to examine a long queue of spam comments to identify which one is a false positive.

You also have the option to choose what action you would like to take when capthca response is correct:

  • Approve the comment immediately
  • Hold the comment in the moderation queue
  • Put the comment in the spam queue

As of version 1.1.1, you can no longer choose to put comment into spam queue, this is to make things less confusing. If you still want to use such feature, add this to your wp-config.php file:

define('BWP_CAPT_AKISMET_COMMENT_STATUS', 'spam');

Integration with Akismet is disabled by default and before you enable it, be sure to activate Akismet for the integration to work. Akismet is one of the plugins that are included within the core WordPress package, so all you need is an API key, which you can signup for free here: Akismet API key.

Important Notes

  • There is no MailHide facility. This plugin does not provide MailHide’s functionality, simply because I want to keep code size to a minimum for the first release. It will be added in future versions, if enough requests are received.

Hook References

Filter Hooks

Name Usage Arguments
bwp_capt_bypass_caps WordPress capabilities that can bypass a recaptcha
array $caps = array(
    'Read Profile' => 'read',
    'Manage Options' => 'manage_options'
)
bwp_capt_css

CSS used for the Custom Theme

Used for reCAPTCHA v1 only

string $css
bwp_capt_reg_css

Used to replace CSS file for registration

Deprecated since 1.1.1

string $reg_css

Action Hooks

Name Usage
bwp_capt_before_add_captcha Fired before the captcha is shown. Can be used to add custom markups before the captcha form
bwp_recaptcha_add_markups Fired where a recaptcha should be rendered. Mostly used to render the captcha in certain forms

Support this plugin!

This plugin is licensed under GPL version 3, and it needs contributions from the community.

Buy me some special coffees!

My plugins and support for them are free. If you like my work and could buy me some (special) coffees, I would be much appreciated!

Rate this plugin 5 stars

If you find this plugin useful, please consider giving it a five-shining-star rating, thank you!

Report issues

Before reporting a new issue, please make sure that you have:

  • read thoroughly the FAQ section of this plugin (there might be none)
  • checked BWP Community for possibly similar issues

If none of the above help, please report found issue to the Github issue tracker. Alternatively, you can report issues to WordPress.org’s support forum, and they will be moved to Github eventually whenever needed.

Please do NOT report issues using the contact form. All issues reported via the contact form will be ignored.

i18n (Translate the plugin)

If you are a translator, please help translating this plugin. Even if you aren’t, you can become one, it is very easy and fun! If you want to know how, please read here: Create a .pot or .po File using Poedit.

References

  1. http://codex.wordpress.org/Function_Reference/comment_f ... mment_form []
Print Article Watch Log