I have a template for contact us page which includes a small form with few text fields. I want to add Recaptcha to avoid spams. I already use WP-recaptch plugin which only works for default Registration and comment form. If follow these instructions from recaptcha docs, I get error the same class instance is being declared twice. Thats becoz recaptchalib.php is used by WP-repatcha already. This error will occur even if I use Contact 7 form plugin with recaptcha as every such plugin going to redeclare the same class.

I include recaptchalib.php from WP_captcha plugin to my template file and it works well to show Recaptcha box, but it doesnt works at validation part - below code doesnt work:

    require_once ( WP_PLUGIN_DIR . '/wp-recaptcha/recaptchalib.php');
    $privatekey = "my key";
    if (empty($_POST['recaptcha_response_field']) || $_POST['recaptcha_response_field'] == '') {
        $captchaErr = 'Please Enter recaptcha text';
    $hasError = true;
      $resp = recaptcha_check_answer ($privatekey,

      if (!$resp->is_valid) {
        // What happens when the CAPTCHA was entered incorrectly - show error

Please can someone suggest a solution?

1 Answer 1


You could try something like

if( ! function_exists('plugin_function') )

Not tested but essentially it checks if the plugin exists before trying to add it

  • including a URL gives this error "wrapper is disabled in the server configuration by allow_url_include=0", as it generates http request Jan 19, 2014 at 23:20
  • Edited my answer, basically PHP doesn't want you to load files from the same server while using the full URL. Jan 19, 2014 at 23:26
  • 1
    It's best to use appropriate constant, such as WP_PLUGIN_DIR, when forming local paths to files. Including from URLs is bad idea, shouldn't be done.
    – Rarst
    Jan 20, 2014 at 0:09
  • WP_PLUGIN_DIR worked well to show the recaptcha box, but it doesnt work at validation part. Jan 20, 2014 at 1:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.