Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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;
   }else{
      $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

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

Please can someone suggest a solution?

share|improve this question

1 Answer 1

You could try something like

if( ! function_exists('plugin_function') )
 require_once('/wp-content/plugins/wp-recaptcha/recaptchalib.php');
endif;

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

share|improve this answer
    
including a URL gives this error "wrapper is disabled in the server configuration by allow_url_include=0", as it generates http request –  user2341459 Jan 19 at 23:20
    
Edited my answer, basically PHP doesn't want you to load files from the same server while using the full URL. –  Gareth Gillman Jan 19 at 23:26
    
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 at 0:09
    
WP_PLUGIN_DIR worked well to show the recaptcha box, but it doesnt work at validation part. –  user2341459 Jan 20 at 1:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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