WordPress ReCaptcha Integration - Version 1.2.1

Version Description

  • Drop most of Contact form 7 and Ninja Forms support. (Both have their own recaptcha now)
  • Register Form compatibility with WooCommerce 3.0+ Thanks to ywatt and MrFent37
  • Fix WSOD
Download this release

Release Info

Developer podpirate
Plugin Icon 128x128 WordPress ReCaptcha Integration
Version 1.2.1
Comparing to
See all releases

Code changes from version 1.2.0 to 1.2.1

composer.json DELETED
@@ -1,17 +0,0 @@
1
- {
2
- "name": "mcguffin/wp-recaptcha-integration",
3
- "type": "wordpress-plugin",
4
- "license": "GPLv2",
5
- "description": "WordPress reCaptcha integration supporting Ninja Forms and Contact Form 7",
6
- "keywords": [
7
- "wordpress",
8
- "plugin",
9
- "recaptcha",
10
- "contact form 7",
11
- "ninja forms",
12
- "captcha"
13
- ],
14
- "require": {
15
- "php": ">=5.2.4"
16
- }
17
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inc/class-wp_recaptcha_awesome_support.php CHANGED
File without changes
inc/class-wp_recaptcha_cforms2.php CHANGED
File without changes
inc/class-wp_recaptcha_contactform7.php CHANGED
@@ -29,211 +29,29 @@ class WP_reCaptcha_ContactForm7 {
29
  * Prevent from creating more than one instance
30
  */
31
  private function __construct() {
32
-
33
- $wpcf7_version = defined('WPCF7_VERSION') ? WPCF7_VERSION : '0';
34
- $wpcf7_recaptcha_configured = class_exists('WPCF7_RECAPTCHA') && ($cf7_sitekey = WPCF7_RECAPTCHA::get_instance()->get_sitekey()) && WPCF7_RECAPTCHA::get_instance()->get_secret( $cf7_sitekey );
35
-
36
- // Skip WPCF7 reCaptcha
37
- if ( $wpcf7_recaptcha_configured || version_compare( $wpcf7_version , '4.3' , '<' ) ) {
38
- add_action( 'wpcf7_init', array( &$this , 'add_shortcode_recaptcha' ) );
39
- add_action( 'wp_enqueue_scripts' , array( &$this , 'recaptcha_enqueue_script') );
40
- add_action( 'admin_init', array( &$this , 'add_tag_generator_recaptcha' ), 45 );
41
- add_filter( 'wpcf7_validate_recaptcha', array( &$this , 'recaptcha_validation_filter' ) , 10, 2 );
42
- add_filter( 'wpcf7_validate_recaptcha*', array( &$this , 'recaptcha_validation_filter' ) , 10, 2 );
43
- add_filter( 'wpcf7_messages' , array( &$this , 'add_error_message' ) );
44
- }
45
- }
46
-
47
-
48
-
49
- function add_error_message( $messages ) {
50
- $messages['wp_recaptcha_invalid'] = array(
51
- 'description' => __( "Google reCaptcha does not validate.", 'wp-recaptcha-integration' ),
52
- 'default' => __("The Captcha didn’t verify.",'wp-recaptcha-integration')
53
- );
54
- return $messages;
55
- }
56
-
57
- function add_shortcode_recaptcha() {
58
- wpcf7_add_shortcode(
59
- array( 'recaptcha','recaptcha*'),
60
- array(&$this,'recaptcha_shortcode_handler'), true );
61
- }
62
-
63
-
64
-
65
- function recaptcha_shortcode_handler( $tag ) {
66
- if ( ! WP_reCaptcha::instance()->is_required() )
67
- return apply_filters( 'wp_recaptcha_disabled_html' ,'');
68
- $tag = new WPCF7_Shortcode( $tag );
69
- if ( empty( $tag->name ) )
70
- return '';
71
-
72
- $atts = null;
73
- if ( $theme = $tag->get_option('theme','',true) )
74
- $atts = array( 'data-theme' => $theme );
75
-
76
- $recaptcha_html = WP_reCaptcha::instance()->recaptcha_html( $atts );
77
- $validation_error = wpcf7_get_validation_error( $tag->name );
78
-
79
- $html = sprintf(
80
- apply_filters( 'wp_recaptcha_cf7_shortcode_wrap' ,'<span class="wpcf7-form-control-wrap %1$s">%2$s %3$s</span>' ),
81
- $tag->name, $recaptcha_html, $validation_error );
82
-
83
- return $html;
84
- }
85
-
86
- function recaptcha_enqueue_script() {
87
- if ( apply_filters( 'wp_recaptcha_do_scripts' , true ) ) {
88
- wp_enqueue_script('wpcf7-recaptcha-integration',plugins_url('/js/wpcf7.js',dirname(__FILE__)),array('contact-form-7'));
89
- }
90
  }
91
 
92
-
93
-
94
- function add_tag_generator_recaptcha() {
95
- if ( ! function_exists( 'wpcf7_add_tag_generator' ) )
96
  return;
97
- wpcf7_add_tag_generator( 'recaptcha', __( 'reCAPTCHA', 'wp-recaptcha-integration' ),
98
- 'wpcf7-tg-pane-recaptcha', array(&$this,'recaptcha_settings_callback') );
99
- }
100
-
101
-
102
-
103
- function recaptcha_settings_callback( $contact_form , $args = '' ) {
104
- $args = wp_parse_args( $args, array() );
105
- $type = 'recaptcha';
106
- if ( defined( 'WPCF7_VERSION') && version_compare( WPCF7_VERSION , '4.2' ) >= 0 ) {
107
- ?>
108
- <div class="control-box">
109
- <fieldset>
110
- <legend><?php _e( 'reCAPTCHA', 'wp-recaptcha-integration' ) ?></legend>
111
-
112
- <table class="form-table">
113
- <tbody>
114
-
115
- <tr>
116
- <th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
117
- <td>
118
- <fieldset>
119
- <legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
120
- <label><input type="checkbox" checked="checked" disabled="disabled" name="required" onclick="return false" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
121
- </fieldset>
122
- </td>
123
- </tr>
124
-
125
- <tr>
126
- <th scope="row"><?php esc_html_e( __( 'Name', 'contact-form-7' ) ); ?></th>
127
- <td>
128
- <fieldset>
129
- <legend class="screen-reader-text"><?php esc_html_e( __( 'Name', 'contact-form-7' ) ); ?></legend>
130
- <label><input type="text" name="name" class="tg-name oneline" /></label>
131
- </fieldset>
132
- </td>
133
- </tr><?php
134
-
135
- if ( 'grecaptcha' === WP_reCaptcha::instance()->get_option('recaptcha_flavor') ) {
136
- ?><tr>
137
- <th scope="row"><?php esc_html_e( __( 'Theme', 'wp-recaptcha-integration' ) ); ?></th>
138
- <td>
139
- <fieldset>
140
- <legend class="screen-reader-text"><?php esc_html_e( __( 'Theme', 'wp-recaptcha-integration' ) ); ?></legend>
141
- <label><?php
142
- $this->_theme_select();
143
- ?></label>
144
- </fieldset>
145
- </td>
146
- </tr><?php
147
- }
148
- ?></tbody>
149
- </table>
150
- </fieldset>
151
- </div>
152
- <div class="insert-box">
153
- <input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
154
-
155
- <div class="submitbox">
156
- <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
157
- </div>
158
-
159
- <br class="clear" />
160
-
161
- <p class="description recaptcha-tag">
162
- <label for="<?php echo esc_attr( $args['content'] . '-recaptchatag' ); ?>">
163
- <?php /* esc_html_e( __( "Foobar", 'contact-form-7' ), '<strong><span class="recaptcha-tag"></span></strong>' );*/ ?>
164
- <input type="text" class="recaptcha-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-recaptchatag' ); ?>" />
165
- </label>
166
- </p>
167
- </div>
168
- <?php
169
- } else {
170
- ?>
171
- <div id="wpcf7-tg-pane-<?php echo $type; ?>" class="_hidden">
172
- <form action="">
173
- <table>
174
- <tr><td><input type="checkbox" checked="checked" disabled="disabled" name="required" onclick="return false" />&nbsp;<?php echo esc_html( __( 'Required field?', 'contact-form-7' ) ); ?></td></tr>
175
- <tr><td>
176
- <?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?><br />
177
- <input type="text" name="name" class="tg-name oneline" />
178
- </td><td><?php
179
- if ( 'grecaptcha' === WP_reCaptcha::instance()->get_option('recaptcha_flavor') ) {
180
-
181
- esc_html_e( __( 'Theme', 'wp-recaptcha-integration' ) ); ?><br /><?php
182
- $this->_theme_select();
183
- // cf7 does only allow literal <input>
184
- }
185
- ?></td></tr>
186
- </table>
187
- <div class="tg-tag">
188
- <?php echo esc_html( __( "Copy this code and paste it into the form left.", 'contact-form-7' ) ); ?><br />
189
- <input type="text" name="<?php echo $type; ?>" class="tag wp-ui-text-highlight code" readonly="readonly" onfocus="this.select()" />
190
- </div>
191
- </form>
192
- </div>
193
- <?php
194
  }
195
- ?><script type="text/javascript">
196
- (function($){
197
- $(document).on('change','[name="recaptcha-theme-ui"]',function(){
198
- $(this).next('[name="theme"]').val( $(this).val() ).trigger('change');
199
- });
200
- })(jQuery)
201
- </script><?php
202
- }
203
-
204
- private function _theme_select() {
205
- $themes = WP_reCaptcha::instance()->captcha_instance()->get_supported_themes();
206
- ?><select name="recaptcha-theme-ui"><?php
207
- ?><option value=""><?php _e('Use default','wp-recaptcha-integration') ?></option><?php
208
- foreach ( $themes as $theme_name => $theme ) {
209
- ?><option value="<?php echo $theme_name; ?>"><?php echo $theme['label'] ?></option><?php
210
- }
211
- ?></select><?php
212
- ?><input type="hidden" name="theme" class="idvalue option" value="" /><?php
213
- }
214
-
215
- function recaptcha_validation_filter( $result, $tag ) {
216
- if ( ! WP_reCaptcha::instance()->is_required() )
217
- return $result;
218
-
219
- $tag = new WPCF7_Shortcode( $tag );
220
- $name = $tag->name;
221
-
222
- if ( ! WP_reCaptcha::instance()->recaptcha_check() ) {
223
- $message = wpcf7_get_message( 'wp_recaptcha_invalid' );
224
- if ( ! $message )
225
- $message = __("The Captcha didn’t verify.",'wp-recaptcha-integration');
226
-
227
- if ( method_exists($result, 'invalidate' ) ) { // since CF7 4.1
228
- $result->invalidate( $tag , $message );
229
- } else {
230
- $result['valid'] = false;
231
- $result['reason'][$name] = $message;
232
  }
233
  }
234
- return $result;
235
  }
236
-
237
 
238
  }
239
-
29
  * Prevent from creating more than one instance
30
  */
31
  private function __construct() {
32
+ add_action('init',array( $this, 'update_cf7_settings' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  }
34
 
35
+ public function update_cf7_settings() {
36
+ $wr = WP_reCaptcha::instance();
37
+ $wr_configured = $wr->has_api_key();
38
+ if ( ! method_exists( 'WPCF7', 'get_option' ) ) {
39
  return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  }
41
+ $cf7_opt = WPCF7::get_option( 'recaptcha' );
42
+ $cf7_configured = is_array( $cf7_opt );
43
+
44
+ if ( $wr_configured && ! $cf7_configured ) {
45
+ $cf7_opt = array();
46
+ $cf7_opt[ $wr->get_option( 'recaptcha_publickey' ) ] = $wr->get_option( 'recaptcha_privatekey' );
47
+ WPCF7::update_option( 'recaptcha', $cf7_opt );
48
+ } else if ( ! $wr_configured && $cf7_configured ) {
49
+ foreach ( $cf7_opt as $pub => $priv ) {
50
+ $wr->update_option( 'recaptcha_publickey' , $pub );
51
+ $wr->update_option( 'recaptcha_privatekey' , $priv );
52
+ break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  }
54
  }
 
55
  }
 
56
 
57
  }
 
inc/class-wp_recaptcha_ninjaforms.php CHANGED
@@ -27,145 +27,26 @@ class WP_reCaptcha_NinjaForms {
27
  * Prevent from creating more than one instance
28
  */
29
  private function __construct() {
30
- add_action( 'init', array(&$this,'register_field_recaptcha'));
31
- add_action( 'init' , array( &$this , 'late_init' ) , 99 );
32
- add_action( 'wp_footer' , array(&$this,'recaptcha_script'),9999 );
33
- add_filter( 'ninja_forms_field' , array(&$this,'recaptcha_field_data'), 10, 2 );
34
- add_filter( 'ninja_forms_settings' , array( &$this , 'nf_settings' ) );
35
- }
36
- function nf_settings( $settings ) {
37
- if ( ! isset($settings['wp_recaptcha_invalid']) )
38
- $settings['wp_recaptcha_invalid'] = __("The Captcha didn’t verify.",'wp-recaptcha-integration');
39
- return $settings;
40
- }
41
- function late_init() {
42
- global $ninja_forms_tabs_metaboxes;
43
-
44
- $ninja_forms_tabs_metaboxes['ninja-forms-settings']['label_settings']['label_labels']['settings'][] = array(
45
- 'name' => 'wp_recaptcha_invalid',
46
- 'type' => 'text',
47
- 'label' => __( "Google reCaptcha does not validate.", 'wp-recaptcha-integration' ),
48
- );
49
- }
50
-
51
- function register_field_recaptcha(){
52
- $args = array(
53
- 'name' => __( 'reCAPTCHA', 'wp-recaptcha-integration' ),
54
- 'edit_function' => '',
55
- 'display_function' => array( &$this , 'field_recaptcha_display' ),
56
- 'group' => 'standard_fields',
57
- 'edit_label' => true,
58
- 'edit_label_pos' => true,
59
- 'edit_req' => false,
60
- 'edit_custom_class' => false,
61
- 'edit_help' => true,
62
- 'edit_meta' => false,
63
- 'sidebar' => 'template_fields',
64
- 'display_label' => true,
65
- 'edit_conditional' => false,
66
- 'conditional' => array(
67
- 'value' => array(
68
- 'type' => 'text',
69
- ),
70
- ),
71
- 'pre_process' => array( &$this , 'field_recaptcha_pre_process' ),
72
- 'process_field' => false,
73
- 'limit' => 1,
74
- 'edit_options' => array(
75
- ),
76
- 'req' => false,
77
- );
78
- if ( 'grecaptcha' === WP_reCaptcha::instance()->get_option('recaptcha_flavor') ) {
79
- $themes = WP_reCaptcha::instance()->captcha_instance()->get_supported_themes();
80
- $edit_options = array(
81
- array( 'name' => __( 'Use default' , 'wp-recaptcha-integration' ) , 'value' => '' ),
82
- );
83
- foreach ( $themes as $theme_name => $theme )
84
- $edit_options[] = array( 'name' => $theme['label'] , 'value' => $theme_name );
85
- $args['edit_options'] = array(
86
- array(
87
- 'type' => 'select',
88
- 'name' => 'theme',
89
- 'label' => __( 'Theme', 'wp-recaptcha-integration' ),
90
- 'width' => 'wide',
91
- 'class' => 'widefat',
92
- 'options' => $edit_options,
93
- ),
94
- );
95
- }
96
-
97
- ninja_forms_register_field('_recaptcha', $args);
98
- }
99
-
100
- function recaptcha_field_data( $data, $field_id ) {
101
- $field_row = ninja_forms_get_field_by_id($field_id);
102
- if ( $field_row['type'] == '_recaptcha' )
103
- $data['show_field'] = WP_reCaptcha::instance()->is_required();
104
- return $data;
105
  }
106
 
107
- function recaptcha_script($id) {
108
- if ( apply_filters( 'wp_recaptcha_do_scripts' , true ) ) {
109
- /*
110
- refresh captcha after form submission.
111
- */
112
- $flavor = WP_reCaptcha::instance()->get_option( 'recaptcha_flavor' );
113
- switch ( $flavor ) {
114
- case 'recaptcha':
115
- $html = '<script type="text/javascript">
116
- // reload recaptcha after failed ajax form submit
117
- jQuery(document).on("submitResponse.default", function(e, response){
118
- Recaptcha.reload();
119
- });
120
- </script>';
121
- break;
122
- case 'grecaptcha':
123
- $html = '<script type="text/javascript">
124
- // reload recaptcha after failed ajax form submit
125
- (function($){
126
- $(document).on("submitResponse.default", function(e, response){
127
- if ( grecaptcha ) {
128
- var wid = $(\'#ninja_forms_form_\'+response.form_id).find(\'.g-recaptcha\').data(\'widget-id\');
129
- grecaptcha.reset(wid);
130
- }
131
- });
132
- })(jQuery);
133
- </script>';
134
- break;
135
- }
136
- WP_reCaptcha::instance()->begin_inject(false,', Ninja form integration');
137
- echo $html;
138
- WP_reCaptcha::instance()->end_inject();
139
- }
140
- }
141
 
142
- function field_recaptcha_display($field_id, $data){
143
- if ( WP_reCaptcha::instance()->is_required() ) {
144
- $attr = !empty($data['theme']) ? array( 'data-theme' => $data['theme'] ) : null;
145
- WP_reCaptcha::instance()->print_recaptcha_html( $attr );
146
- } else {
147
- echo apply_filters( 'wp_recaptcha_disabled_html' ,'');
148
  }
149
- }
150
-
151
- function field_recaptcha_pre_process( $field_id, $user_value ){
152
- global $ninja_forms_processing;
153
- $plugin_settings = nf_get_settings();
154
-
155
- $recaptcha_error = __("The Captcha didn’t verify.",'wp-recaptcha-integration');
156
- if ( isset( $plugin_settings['wp_recaptcha_invalid'] ) )
157
- $recaptcha_error = $plugin_settings['wp_recaptcha_invalid'];
158
 
159
- $field_row = ninja_forms_get_field_by_id($field_id);
160
- $field_data = $field_row['data'];
161
- $form_row = ninja_forms_get_form_by_field_id($field_id);
162
- $form_id = $form_row['id'];
163
-
164
- $require_recaptcha = WP_reCaptcha::instance()->is_required();
165
-
166
- if ( $ninja_forms_processing->get_action() != 'save' && $ninja_forms_processing->get_action() != 'mp_save' && $require_recaptcha && ! WP_reCaptcha::instance()->recaptcha_check() ){
167
- $ninja_forms_processing->add_error('recaptcha-general', $recaptcha_error, 'general');
168
- $ninja_forms_processing->add_error('recaptcha-'.$field_id, $recaptcha_error, $field_id);
169
  }
170
  }
 
171
  }
27
  * Prevent from creating more than one instance
28
  */
29
  private function __construct() {
30
+ add_action('init', array( $this, 'update_nf_settings' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  }
32
 
33
+ function update_nf_settings( ) {
34
+ $nf = Ninja_Forms();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
+ if ( ! method_exists( $nf, 'get_setting' ) ) {
37
+ return;
 
 
 
 
38
  }
 
 
 
 
 
 
 
 
 
39
 
40
+ $wr = WP_reCaptcha::instance();
41
+ $wr_configured = $wr->has_api_key();
42
+ $nf_configured = false !== $nf->get_setting('recaptcha_site_key') && false !== $nf->get_setting('recaptcha_secret_key');
43
+ if ( $wr_configured && ! $nf_configured ) {
44
+ $nf->update_setting( 'recaptcha_site_key', $wr->get_option( 'recaptcha_publickey' ) );
45
+ $nf->update_setting( 'recaptcha_secret_key', $wr->get_option( 'recaptcha_privatekey' ) );
46
+ } else if ( ! $wr_configured && $nf_configured ) {
47
+ $wr->update_option( 'recaptcha_publickey' , $nf->get_setting('recaptcha_site_key') );
48
+ $wr->update_option( 'recaptcha_privatekey' , $nf->get_setting('recaptcha_secret_key') );
 
49
  }
50
  }
51
+
52
  }
inc/class-wp_recaptcha_nocaptcha.php CHANGED
@@ -6,58 +6,83 @@
6
  * Class to manage the recaptcha options.
7
  */
8
  class WP_reCaptcha_NoCaptcha extends WP_reCaptcha_Captcha {
9
-
10
  protected $supported_languages = array(
11
- 'ar' => 'Arabic',
12
- 'bg' => 'Bulgarian',
13
- 'ca' => 'Catalan',
14
- 'zh-CN' => 'Chinese (Simplified)',
15
- 'zh-TW' => 'Chinese (Traditional)',
16
- 'hr' => 'Croatian',
17
- 'cs' => 'Czech',
18
- 'da' => 'Danish',
19
- 'nl' => 'Dutch',
20
- 'en-GB' => 'English (UK)',
21
- 'en' => 'English (US)',
22
- 'fil' => 'Filipino',
23
- 'fi' => 'Finnish',
24
- 'fr' => 'French',
25
- 'fr-CA' => 'French (Canadian)',
26
- 'de' => 'German',
27
- 'de-AT' => 'German (Austria)',
28
- 'de-CH' => 'German (Switzerland)',
29
- 'el' => 'Greek',
30
- 'iw' => 'Hebrew',
31
- 'hi' => 'Hindi',
32
- 'hu' => 'Hungarain',
33
- 'id' => 'Indonesian',
34
- 'it' => 'Italian',
35
- 'ja' => 'Japanese',
36
- 'ko' => 'Korean',
37
- 'lv' => 'Latvian',
38
- 'lt' => 'Lithuanian',
39
- 'no' => 'Norwegian',
40
- 'fa' => 'Persian',
41
- 'pl' => 'Polish',
42
- 'pt' => 'Portuguese',
43
- 'pt-BR' => 'Portuguese (Brazil)',
44
- 'pt-PT' => 'Portuguese (Portugal)',
45
- 'ro' => 'Romanian',
46
- 'ru' => 'Russian',
47
- 'sr' => 'Serbian',
48
- 'sk' => 'Slovak',
49
- 'sl' => 'Slovenian',
50
- 'es' => 'Spanish',
51
- 'es-419' => 'Spanish (Latin America)',
52
- 'sv' => 'Swedish',
53
- 'th' => 'Thai',
54
- 'tr' => 'Turkish',
55
- 'uk' => 'Ukrainian',
56
- 'vi' => 'Vietnamese',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  );
58
  private $_counter = 0;
59
-
60
-
61
  /**
62
  * Holding the singleton instance
63
  */
@@ -96,8 +121,8 @@ class WP_reCaptcha_NoCaptcha extends WP_reCaptcha_Captcha {
96
  /**
97
  * Override method
98
  * Get recaptcha language code that matches input language code
99
- * Sometimes WP uses different locales the the ones supported by nocaptcha.
100
- *
101
  * @param $lang string language code
102
  * @return string recaptcha language code if supported by current flavor, empty string otherwise
103
  */
@@ -138,11 +163,11 @@ class WP_reCaptcha_NoCaptcha extends WP_reCaptcha_Captcha {
138
  public function print_foot() {
139
  $sitekey = WP_reCaptcha::instance()->get_option('recaptcha_publickey');
140
  $language_param = '';
141
-
142
-
143
  ?><script type="text/javascript">
144
  var recaptcha_widgets={};
145
- function wp_recaptchaLoadCallback(){
146
  try {
147
  grecaptcha;
148
  } catch(err){
@@ -163,7 +188,7 @@ class WP_reCaptcha_NoCaptcha extends WP_reCaptcha_Captcha {
163
  wid = grecaptcha.render(el,{
164
  'sitekey':'<?php echo $sitekey ?>',
165
  'theme':el.getAttribute('data-theme') || '<?php echo WP_reCaptcha::instance()->get_option('recaptcha_theme'); ?>'
166
- <?php if ( WP_reCaptcha::instance()->get_option( 'recaptcha_disable_submit' ) ) {
167
  ?> ,
168
  'callback' : function(r){ get_form_submits(el).setEnabled(true); /* enable submit buttons */ }
169
  <?php } ?>
@@ -176,14 +201,14 @@ class WP_reCaptcha_NoCaptcha extends WP_reCaptcha_Captcha {
176
  })(e[i]);
177
  }
178
  }
179
-
180
- // if jquery present re-render jquery/ajax loaded captcha elements
181
  if ( typeof jQuery !== 'undefined' )
182
  jQuery(document).ajaxComplete( function(evt,xhr,set){
183
  if( xhr.responseText && xhr.responseText.indexOf('<?php echo $sitekey ?>') !== -1)
184
  wp_recaptchaLoadCallback();
185
  } );
186
-
187
  </script><?php
188
  $recaptcha_api_url = "https://www.google.com/recaptcha/api.js";
189
  $recaptcha_api_url = add_query_arg(array(
@@ -192,12 +217,12 @@ class WP_reCaptcha_NoCaptcha extends WP_reCaptcha_Captcha {
192
  ),$recaptcha_api_url);
193
  if ( $language_code = apply_filters( 'wp_recaptcha_language' , WP_reCaptcha::instance()->get_option( 'recaptcha_language' ) ) )
194
  $recaptcha_api_url = add_query_arg('hl',$language_code,$recaptcha_api_url);
195
-
196
  ?><script src="<?php echo esc_url( $recaptcha_api_url ) ?>" async defer></script><?php
197
  }
198
-
199
-
200
-
201
  /**
202
  * @inheritdoc
203
  */
@@ -212,7 +237,7 @@ class WP_reCaptcha_NoCaptcha extends WP_reCaptcha_Captcha {
212
  'data-theme' => $theme,
213
  );
214
  $attr = wp_parse_args( $attr , $default );
215
-
216
  $attr_str = '';
217
  foreach ( $attr as $attr_name => $attr_val )
218
  $attr_str .= sprintf( ' %s="%s"' , $attr_name , esc_attr( $attr_val ) );
@@ -268,5 +293,5 @@ class WP_reCaptcha_NoCaptcha extends WP_reCaptcha_Captcha {
268
  return false;
269
  }
270
 
271
-
272
  }
6
  * Class to manage the recaptcha options.
7
  */
8
  class WP_reCaptcha_NoCaptcha extends WP_reCaptcha_Captcha {
9
+
10
  protected $supported_languages = array(
11
+ 'ar' => 'Arabic',
12
+ 'af' => 'Afrikaans',
13
+ 'am' => 'Amharic',
14
+ 'hy' => 'Armenian',
15
+ 'az' => 'Azerbaijani',
16
+ 'eu' => 'Basque',
17
+ 'bn' => 'Bengali',
18
+ 'bg' => 'Bulgarian',
19
+ 'ca' => 'Catalan',
20
+ 'zh-HK' => 'Chinese (Hong Kong)',
21
+ 'zh-CN' => 'Chinese (Simplified)',
22
+ 'zh-TW' => 'Chinese (Traditional)',
23
+ 'hr' => 'Croatian',
24
+ 'cs' => 'Czech',
25
+ 'da' => 'Danish',
26
+ 'nl' => 'Dutch',
27
+ 'en-GB' => 'English (UK)',
28
+ 'en' => 'English (US)',
29
+ 'et' => 'Estonian',
30
+ 'fil' => 'Filipino',
31
+ 'fi' => 'Finnish',
32
+ 'fr' => 'French',
33
+ 'fr-CA' => 'French (Canadian)',
34
+ 'gl' => 'Galician',
35
+ 'ka' => 'Georgian',
36
+ 'de' => 'German',
37
+ 'de-AT' => 'German (Austria)',
38
+ 'de-CH' => 'German (Switzerland)',
39
+ 'el' => 'Greek',
40
+ 'gu' => 'Gujarati',
41
+ 'iw' => 'Hebrew',
42
+ 'hi' => 'Hindi',
43
+ 'hu' => 'Hungarain',
44
+ 'is' => 'Icelandic',
45
+ 'id' => 'Indonesian',
46
+ 'it' => 'Italian',
47
+ 'ja' => 'Japanese',
48
+ 'kn' => 'Kannada',
49
+ 'ko' => 'Korean',
50
+ 'lo' => 'Laothian',
51
+ 'lv' => 'Latvian',
52
+ 'lt' => 'Lithuanian',
53
+ 'ms' => 'Malay',
54
+ 'ml' => 'Malayalam',
55
+ 'mr' => 'Marathi',
56
+ 'mn' => 'Mongolian',
57
+ 'no' => 'Norwegian',
58
+ 'fa' => 'Persian',
59
+ 'Value' => 'Language',
60
+ 'pl' => 'Polish',
61
+ 'pt' => 'Portuguese',
62
+ 'pt-BR' => 'Portuguese (Brazil)',
63
+ 'pt-PT' => 'Portuguese (Portugal)',
64
+ 'ro' => 'Romanian',
65
+ 'ru' => 'Russian',
66
+ 'sr' => 'Serbian',
67
+ 'si' => 'Sinhalese',
68
+ 'sk' => 'Slovak',
69
+ 'sl' => 'Slovenian',
70
+ 'es' => 'Spanish',
71
+ 'es-419' => 'Spanish (Latin America)',
72
+ 'sw' => 'Swahili',
73
+ 'sv' => 'Swedish',
74
+ 'ta' => 'Tamil',
75
+ 'te' => 'Telugu',
76
+ 'th' => 'Thai',
77
+ 'tr' => 'Turkish',
78
+ 'uk' => 'Ukrainian',
79
+ 'ur' => 'Urdu',
80
+ 'vi' => 'Vietnamese',
81
+ 'zu' => 'Zulu',
82
  );
83
  private $_counter = 0;
84
+
85
+
86
  /**
87
  * Holding the singleton instance
88
  */
121
  /**
122
  * Override method
123
  * Get recaptcha language code that matches input language code
124
+ * Sometimes WP uses different locales the the ones supported by nocaptcha.
125
+ *
126
  * @param $lang string language code
127
  * @return string recaptcha language code if supported by current flavor, empty string otherwise
128
  */
163
  public function print_foot() {
164
  $sitekey = WP_reCaptcha::instance()->get_option('recaptcha_publickey');
165
  $language_param = '';
166
+
167
+
168
  ?><script type="text/javascript">
169
  var recaptcha_widgets={};
170
+ function wp_recaptchaLoadCallback(){
171
  try {
172
  grecaptcha;
173
  } catch(err){
188
  wid = grecaptcha.render(el,{
189
  'sitekey':'<?php echo $sitekey ?>',
190
  'theme':el.getAttribute('data-theme') || '<?php echo WP_reCaptcha::instance()->get_option('recaptcha_theme'); ?>'
191
+ <?php if ( WP_reCaptcha::instance()->get_option( 'recaptcha_disable_submit' ) ) {
192
  ?> ,
193
  'callback' : function(r){ get_form_submits(el).setEnabled(true); /* enable submit buttons */ }
194
  <?php } ?>
201
  })(e[i]);
202
  }
203
  }
204
+
205
+ // if jquery present re-render jquery/ajax loaded captcha elements
206
  if ( typeof jQuery !== 'undefined' )
207
  jQuery(document).ajaxComplete( function(evt,xhr,set){
208
  if( xhr.responseText && xhr.responseText.indexOf('<?php echo $sitekey ?>') !== -1)
209
  wp_recaptchaLoadCallback();
210
  } );
211
+
212
  </script><?php
213
  $recaptcha_api_url = "https://www.google.com/recaptcha/api.js";
214
  $recaptcha_api_url = add_query_arg(array(
217
  ),$recaptcha_api_url);
218
  if ( $language_code = apply_filters( 'wp_recaptcha_language' , WP_reCaptcha::instance()->get_option( 'recaptcha_language' ) ) )
219
  $recaptcha_api_url = add_query_arg('hl',$language_code,$recaptcha_api_url);
220
+
221
  ?><script src="<?php echo esc_url( $recaptcha_api_url ) ?>" async defer></script><?php
222
  }
223
+
224
+
225
+
226
  /**
227
  * @inheritdoc
228
  */
237
  'data-theme' => $theme,
238
  );
239
  $attr = wp_parse_args( $attr , $default );
240
+
241
  $attr_str = '';
242
  foreach ( $attr as $attr_name => $attr_val )
243
  $attr_str .= sprintf( ' %s="%s"' , $attr_name , esc_attr( $attr_val ) );
293
  return false;
294
  }
295
 
296
+
297
  }
inc/class-wp_recaptcha_woocommerce.php CHANGED
@@ -58,7 +58,16 @@ class WP_reCaptcha_WooCommerce {
58
  add_filter('woocommerce_process_login_errors', array( &$this , 'login_errors' ) , 10 , 3 );
59
  }
60
  if ( $enable_signup ) {
61
- // displaying the captcha at hook 'registration_form' already done by core plugin
 
 
 
 
 
 
 
 
 
62
  add_filter('woocommerce_registration_errors', array( &$this , 'login_errors' ) , 10 , 3 );
63
  // if ( ! $enable_order )
64
  // add_filter('woocommerce_checkout_fields', array( &$this , 'checkout_fields' ) , 10 , 3 );
@@ -146,20 +155,20 @@ class WP_reCaptcha_WooCommerce {
146
  * hooks into action `woocommerce_checkout_process`
147
  */
148
  function recaptcha_check() {
149
- if ( ! WP_reCaptcha::instance()->recaptcha_check() )
150
  wc_add_notice( __("<strong>Error:</strong> the Captcha didn’t verify.",'wp-recaptcha-integration'), 'error' );
151
  }
152
-
153
  /**
154
  * WooCommerce recaptcha Check
155
  * hooks into actions `woocommerce_process_login_errors` and `woocommerce_registration_errors`
156
  */
157
  function login_errors( $validation_error ) {
158
- if ( ! WP_reCaptcha::instance()->recaptcha_check() )
159
  $validation_error->add( 'captcha_error' , __("<strong>Error:</strong> the Captcha didn’t verify.",'wp-recaptcha-integration') );
160
  return $validation_error;
161
  }
162
-
163
  /**
164
  * WooCommerce recaptcha Check
165
  * hooks into actions `woocommerce_process_login_errors` and `woocommerce_registration_errors`
@@ -170,5 +179,3 @@ class WP_reCaptcha_WooCommerce {
170
  return $enabled;
171
  }
172
  }
173
-
174
-
58
  add_filter('woocommerce_process_login_errors', array( &$this , 'login_errors' ) , 10 , 3 );
59
  }
60
  if ( $enable_signup ) {
61
+ // Injects recaptcha in Register for WooCommerce >= 3.0
62
+ // For WooCommerce < 3.0 displaying the captcha at hook 'registration_form' already done by core plugin
63
+ if ( class_exists( 'WooCommerce' ) ) {
64
+ global $woocommerce;
65
+ if ( version_compare( $woocommerce->version, '3.0', ">=" ) ) {
66
+ add_action('woocommerce_register_form' , array($wp_recaptcha,'print_recaptcha_html'),10,0);
67
+ }
68
+ }
69
+
70
+
71
  add_filter('woocommerce_registration_errors', array( &$this , 'login_errors' ) , 10 , 3 );
72
  // if ( ! $enable_order )
73
  // add_filter('woocommerce_checkout_fields', array( &$this , 'checkout_fields' ) , 10 , 3 );
155
  * hooks into action `woocommerce_checkout_process`
156
  */
157
  function recaptcha_check() {
158
+ if ( ! WP_reCaptcha::instance()->recaptcha_check() )
159
  wc_add_notice( __("<strong>Error:</strong> the Captcha didn’t verify.",'wp-recaptcha-integration'), 'error' );
160
  }
161
+
162
  /**
163
  * WooCommerce recaptcha Check
164
  * hooks into actions `woocommerce_process_login_errors` and `woocommerce_registration_errors`
165
  */
166
  function login_errors( $validation_error ) {
167
+ if ( ! WP_reCaptcha::instance()->recaptcha_check() )
168
  $validation_error->add( 'captcha_error' , __("<strong>Error:</strong> the Captcha didn’t verify.",'wp-recaptcha-integration') );
169
  return $validation_error;
170
  }
171
+
172
  /**
173
  * WooCommerce recaptcha Check
174
  * hooks into actions `woocommerce_process_login_errors` and `woocommerce_registration_errors`
179
  return $enabled;
180
  }
181
  }
 
 
inc/woocommerce/myaccount/form-lost-password.php CHANGED
File without changes
languages/wp-recaptcha-integration-cs_CZ.mo CHANGED
File without changes
languages/wp-recaptcha-integration-cs_CZ.po CHANGED
File without changes
languages/wp-recaptcha-integration-de_DE.mo CHANGED
File without changes
languages/wp-recaptcha-integration-de_DE.po CHANGED
File without changes
languages/wp-recaptcha-integration-es_ES.mo CHANGED
File without changes
languages/wp-recaptcha-integration-es_ES.po CHANGED
File without changes
languages/wp-recaptcha-integration-it_IT.mo CHANGED
File without changes
languages/wp-recaptcha-integration-it_IT.po CHANGED
File without changes
languages/wp-recaptcha-integration-pt_BR.mo CHANGED
File without changes
languages/wp-recaptcha-integration-pt_BR.po CHANGED
File without changes
languages/wp-recaptcha-integration-pt_PT.mo CHANGED
File without changes
languages/wp-recaptcha-integration-pt_PT.po CHANGED
File without changes
readme.txt CHANGED
@@ -257,6 +257,11 @@ Since late 2015 WordPress.org offers a plugin translation API. Just use the
257
 
258
  == Changelog ==
259
 
 
 
 
 
 
260
  = 1.2.0 =
261
  - Support [cformsII](https://wordpress.org/plugins/cforms2/) (thanks to [Bastian Germann](https://github.com/bgermann))
262
  - Support for Password Reset Protection for older woocommerce Versions [ingomarent](https://github.com/ingomarent)
257
 
258
  == Changelog ==
259
 
260
+ = 1.2.1 =
261
+ - Drop most of Contact form 7 and Ninja Forms support. (Both have their own recaptcha now)
262
+ - Register Form compatibility with WooCommerce 3.0+ Thanks to [ywatt](https://github.com/ingomarent) and [MrFent37](https://wordpress.org/support/users/mrfent37/)
263
+ - Fix WSOD
264
+
265
  = 1.2.0 =
266
  - Support [cformsII](https://wordpress.org/plugins/cforms2/) (thanks to [Bastian Germann](https://github.com/bgermann))
267
  - Support for Password Reset Protection for older woocommerce Versions [ingomarent](https://github.com/ingomarent)
wp-recaptcha-integration.php CHANGED
@@ -2,8 +2,8 @@
2
  /*
3
  Plugin Name: WP reCaptcha Integration
4
  Plugin URI: https://wordpress.org/plugins/wp-recaptcha-integration/
5
- Description: Integrate reCaptcha in your blog. Supports no Captcha (new style recaptcha) as well as the old style reCaptcha. Provides of the box integration for signup, login, comment forms, lost password, Ninja Forms and contact form 7.
6
- Version: 1.2.0
7
  Author: Jörn Lund
8
  Author URI: https://github.com/mcguffin/
9
  Text Domain: wp-recaptcha-integration
@@ -42,7 +42,7 @@ spl_autoload_register( 'wp_recaptcha_integration_autoload' );
42
  function wp_recaptcha_disable_updates($value) {
43
  if ( version_compare(PHP_VERSION, '5.4', '<') ) {
44
  $plugin_basename = plugin_basename(__FILE__);
45
- if ( isset( $value->response[ $plugin_basename ] ) && version_compare( $value->response[ $plugin_basename ]['new_version'] , '2.0.0', '>=' ) ) {
46
  unset( $value->response[ plugin_basename(__FILE__) ] );
47
  }
48
  }
@@ -50,7 +50,6 @@ function wp_recaptcha_disable_updates($value) {
50
  }
51
  add_filter('site_transient_update_plugins', 'wp_recaptcha_disable_updates');
52
 
53
-
54
  WP_reCaptcha::instance();
55
 
56
 
2
  /*
3
  Plugin Name: WP reCaptcha Integration
4
  Plugin URI: https://wordpress.org/plugins/wp-recaptcha-integration/
5
+ Description: Integrate reCaptcha in your blog. Supports no Captcha (new style recaptcha). Provides of the box integration for signup, login, comment forms and lost password.
6
+ Version: 1.2.1
7
  Author: Jörn Lund
8
  Author URI: https://github.com/mcguffin/
9
  Text Domain: wp-recaptcha-integration
42
  function wp_recaptcha_disable_updates($value) {
43
  if ( version_compare(PHP_VERSION, '5.4', '<') ) {
44
  $plugin_basename = plugin_basename(__FILE__);
45
+ if ( isset( $value->response[ $plugin_basename ] ) && version_compare( $value->response[ $plugin_basename ]->new_version , '2.0.0', '>=' ) ) {
46
  unset( $value->response[ plugin_basename(__FILE__) ] );
47
  }
48
  }
50
  }
51
  add_filter('site_transient_update_plugins', 'wp_recaptcha_disable_updates');
52
 
 
53
  WP_reCaptcha::instance();
54
 
55