Changeset 1223249
- Timestamp:
- 08/18/2015 03:47:01 AM (10 years ago)
- Location:
- contact-form-7-recaptcha
- Files:
-
- 4 added
- 2 edited
-
tags/1.0.0 (added)
-
tags/1.0.0/index.php (added)
-
tags/1.0.0/readme.txt (added)
-
trunk/index.php (modified) (5 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/script.js (added)
Legend:
- Unmodified
- Added
- Removed
-
contact-form-7-recaptcha/trunk/index.php
r1183076 r1223249 3 3 Plugin Name: Contact Form 7 - reCAPTCHA 4 4 Description: The new reCAPTCHA for Contact Form 7 forms. Use shortcode [recaptcha]. 5 Version: 1. 0.05 Version: 1.1.0 6 6 Author: iambriansreed 7 7 */ … … 47 47 if ( ! empty( $this->site_key ) && ! empty( $this->secret_key ) ) 48 48 { 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 ); 51 51 add_filter( 'wpcf7_validate', array( $this, 'wpcf7_validate' ), 999 ); 52 52 } … … 56 56 } 57 57 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 58 93 function wpcf7_init() 59 94 { … … 61 96 } 62 97 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 68 98 function wpcf7_validate( $result ) 69 { 99 { 70 100 if ( isset( $_POST['contact_form_7_recaptcha'] ) ) 71 101 { 72 102 $error = true; 103 $error_message = $this->error_message; 73 104 74 105 if( ! empty( $_POST['g-recaptcha-response'] ) ) … … 76 107 $url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . $this->secret_key . '&response=' . $_POST['g-recaptcha-response']; 77 108 $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 } 81 128 } 82 129 83 130 if( $error ) 84 131 { 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>'); 86 133 } 87 134 } 88 135 89 136 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 <?php116 wp_print_scripts( 'contact_form_7_recaptcha_script' );117 137 } 118 138 -
contact-form-7-recaptcha/trunk/readme.txt
r1183082 r1223249 3 3 Donate link: http://iambrian.com/ 4 4 Tags: recaptcha, contact form 7, recaptcha v2 5 Requires at least: 4.1. 26 Tested up to: 4. 1.27 Stable tag: 1. 0.05 Requires at least: 4.1.0 6 Tested up to: 4.2.4 7 Stable tag: 1.1.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 28 28 2. Activate the plugin through the 'Plugins' menu in WordPress 29 29 3. 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.