Plugin Directory

Changeset 1223249


Ignore:
Timestamp:
08/18/2015 03:47:01 AM (10 years ago)
Author:
iambriansreed
Message:

added old tag and copied updated code to trunk

Location:
contact-form-7-recaptcha
Files:
4 added
2 edited

Legend:

Unmodified
Added
Removed
  • contact-form-7-recaptcha/trunk/index.php

    r1183076 r1223249  
    33Plugin Name: Contact Form 7 - reCAPTCHA
    44Description: The new reCAPTCHA for Contact Form 7 forms. Use shortcode [recaptcha].
    5 Version: 1.0.0
     5Version: 1.1.0
    66Author: iambriansreed
    77*/
     
    4747            if ( ! empty( $this->site_key ) && ! empty( $this->secret_key ) )
    4848            {
    49                 add_action( 'init', array( $this, 'init' ) );
    50                 add_action( 'wp_footer', array( $this, 'wp_footer' ) );
     49                add_action( 'wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ) );
     50                add_action( 'wp_footer', array( $this, 'wp_footer' ), 999 );
    5151                add_filter( 'wpcf7_validate', array( $this, 'wpcf7_validate' ), 999 );
    5252            }
     
    5656    }
    5757   
     58    function wp_enqueue_scripts()
     59    {   
     60        wp_register_script(
     61            'contact_form_7_recaptcha_script',
     62            plugins_url( '/script.js' , __FILE__ ),
     63            array( 'jquery', 'google_recaptcha_script' ),
     64            '1.0.0',
     65            true
     66        );
     67       
     68        wp_register_script(
     69            'google_recaptcha_script',
     70            'https://www.google.com/recaptcha/api.js?onload=contact_form_7_recaptcha_callback&render=explicit',
     71            array( 'jquery' ),
     72            '1.0.0',
     73            true
     74        );
     75       
     76        wp_localize_script(
     77            'contact_form_7_recaptcha_script',
     78            'contact_form_7_recaptcha_data',
     79            array(
     80                'sitekey' => $this->site_key
     81            )
     82        );
     83    }
     84   
     85    function wp_footer()
     86    {
     87        if( count( $this->ids ) )
     88        {
     89            wp_print_scripts('contact_form_7_recaptcha_script');
     90        }
     91    }
     92   
    5893    function wpcf7_init()
    5994    {
     
    6196    }
    6297   
    63     function init()
    64     {
    65         wp_register_script( 'contact_form_7_recaptcha_script', 'https://www.google.com/recaptcha/api.js?onload=contact_form_7_recaptcha_callback&render=explicit' );
    66     }
    67 
    6898    function wpcf7_validate( $result )
    69     {   
     99    {
    70100        if ( isset( $_POST['contact_form_7_recaptcha'] ) )
    71101        {
    72102            $error = true;
     103            $error_message = $this->error_message;
    73104           
    74105            if( ! empty( $_POST['g-recaptcha-response'] ) )
     
    76107                $url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . $this->secret_key . '&response=' . $_POST['g-recaptcha-response'];
    77108                $request = wp_remote_get( $url );
    78                 $body = wp_remote_retrieve_body( $request );
    79                 $response = json_decode( $body );
    80                 $error = ! ( isset ( $response->success ) && 1 == $response->success );
     109               
     110                if( is_wp_error( $request ) )
     111                {   
     112                    $error = true;
     113                    $error_message = "An error occured when verifying the reCaptcha. The form can not be submitted at this time.";
     114                    if( is_user_logged_in() )
     115                    {
     116                        $error_message .= " The errors reported were:<br>";
     117                        foreach( $request->errors as $k=>$values )
     118                            $error_message .= "<strong>$k</strong>: " . implode( '<br>', $values ) . "<br>";
     119                        $error_message .= "These errors may occur on servers which don't support SSL with cURL.";
     120                    }
     121                }
     122                else
     123                {
     124                    $body = wp_remote_retrieve_body( $request );
     125                    $response = json_decode( $body );
     126                    $error = ! ( isset ( $response->success ) && 1 == $response->success );
     127                }
    81128            }
    82129           
    83130            if( $error )
    84131            {
    85                 $result->invalidate( array( 'type' => 'recaptcha', 'name' => 'g-recaptcha-explicit' ), $this->error_message ); //. '<pre>' . print_r( $request, 1) . '</pre>');
     132                $result->invalidate( array( 'type' => 'recaptcha', 'name' => 'g-recaptcha-explicit' ), $error_message ); //. '<pre>' . print_r( $request, 1) . '</pre>');
    86133            }
    87134        }
    88135       
    89136        return $result;
    90     }
    91    
    92     function wp_footer()
    93     {
    94         if ( ! count( $this->ids ) )
    95         {
    96             return;
    97         }
    98             ?>
    99 <script type="text/javascript">
    100     var contact_form_7_recaptcha_callback = function() {
    101         <?php foreach( $this->ids as $id ): ?>
    102         grecaptcha.render('<?php echo $id ?>', {
    103         'sitekey' : '<?php echo $this->site_key; ?>'
    104         });
    105         <?php endforeach; ?>
    106     };
    107     $('.wpcf7').on('mailsent.wpcf7',function(e){
    108         var id = $('.g-recaptcha-explicit-id', this).val();
    109         $('#' + id).html('');
    110         grecaptcha.render(id, {
    111             'sitekey' : '<?php echo $this->site_key; ?>'
    112         });
    113     });
    114 </script>
    115         <?php
    116         wp_print_scripts( 'contact_form_7_recaptcha_script' );       
    117137    }
    118138           
  • contact-form-7-recaptcha/trunk/readme.txt

    r1183082 r1223249  
    33Donate link: http://iambrian.com/
    44Tags: recaptcha, contact form 7, recaptcha v2
    5 Requires at least: 4.1.2
    6 Tested up to: 4.1.2
    7 Stable tag: 1.0.0
     5Requires at least: 4.1.0
     6Tested up to: 4.2.4
     7Stable tag: 1.1.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    28282. Activate the plugin through the 'Plugins' menu in WordPress
    29293. Configure plugin from Settings -> reCAPTCHA
     30
     31== Changelog ==
     32 
     33= 1.1.0 =
     34* Fixed the jQuery without a jQuery wrapper.
     35* Fixed the javascript queue issues.
     36* Fixed the invalid submission error that would break the recaptcha.
     37* Show wp_error information to logged in users. Note: SSL cURL requests are problematic in certain environments.
     38
     39= 1.0.0 =
     40* Nothing new to see here.
Note: See TracChangeset for help on using the changeset viewer.