WordPress ReCaptcha Integration - Version 1.0.0

Version Description

  • Allow more than one no Captcha per page
  • Test captcha verification in Settings
  • Multisite support.
Download this release

Release Info

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

Code changes from version 0.9.1 to 1.0.0

inc/class-wp-recaptcha-options.php ADDED
@@ -0,0 +1,529 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+
5
+ class WP_reCaptcha_Options {
6
+ private $enter_api_key;
7
+ /**
8
+ * Holding the singleton instance
9
+ */
10
+ private static $_instance = null;
11
+
12
+ /**
13
+ * @return WP_reCaptcha_Options The options manager instance
14
+ */
15
+ public static function instance(){
16
+ if ( is_null( self::$_instance ) )
17
+ self::$_instance = new self();
18
+ return self::$_instance;
19
+ }
20
+
21
+ /**
22
+ * Prevent from creating more than one instance
23
+ */
24
+ private function __clone() {
25
+ }
26
+ /**
27
+ * Prevent from creating more than one instance
28
+ */
29
+ private function __construct() {
30
+ add_action('admin_init', array(&$this,'admin_init') );
31
+ add_action('admin_menu', array(&$this,'add_options_page') );
32
+
33
+ if ( WP_reCaptcha::is_network_activated() ) {
34
+ $page_hook = 'settings_page_racaptcha-settings';
35
+ add_action( "load-{$page_hook}", array( &$this , 'enqueue_styles' ));
36
+ add_action( "load-{$page_hook}", array( &$this , 'process_network_settings' ));
37
+ add_action( 'network_admin_menu', array( &$this , 'network_settings_menu' ));
38
+ }
39
+
40
+ add_action( 'pre_update_option_recaptcha_publickey' , array( &$this , 'update_option_recaptcha_apikey' ) , 10 , 2 );
41
+ add_action( 'pre_update_option_recaptcha_privatekey' , array( &$this , 'update_option_recaptcha_apikey' ) , 10 , 2 );
42
+ add_action( 'add_option_recaptcha_publickey' , array( &$this , 'add_option_recaptcha_apikey' ) , 10 , 2 );
43
+ add_action( 'add_option_recaptcha_privatekey' , array( &$this , 'add_option_recaptcha_apikey' ) , 10 , 2 );
44
+ }
45
+
46
+
47
+ /**
48
+ * Process network options
49
+ */
50
+ function process_network_settings() {
51
+ if ( current_user_can('manage_network') ) {
52
+ $opts = array(
53
+ 'recaptcha_publickey' => 'trim',
54
+ 'recaptcha_privatekey' => 'trim',
55
+ 'recaptcha_enable_comments' => 'intval',
56
+ 'recaptcha_enable_signup' => 'intval',
57
+ 'recaptcha_enable_login' => 'intval',
58
+ 'recaptcha_enable_lostpw' => 'intval',
59
+ 'recaptcha_disable_for_known_users' => 'intval',
60
+ );
61
+ if ( array_intersect( array_keys( $_POST ) , array_keys( $opts ) ) )
62
+ check_admin_referer( 'recaptcha-network-settings' );
63
+
64
+ $updated = false;
65
+ foreach ( $opts as $option_name => $sanitize_cb ) {
66
+ if ( isset( $_POST[ $option_name ] ) ) {
67
+ $option_value = sanitize_text_field( $_POST[ $option_name ] );
68
+ if ( is_callable($sanitize_cb) )
69
+ $option_value = call_user_func($sanitize_cb,$_POST[$option_name]);
70
+ update_site_option( $option_name , $option_value );
71
+ $updated = true;
72
+ }
73
+ }
74
+ if ( $updated ) {
75
+ wp_redirect(add_query_arg('updated','true'));
76
+ }
77
+ } else {
78
+ wp_die('Cheating, uh?');
79
+ }
80
+ // expecting api keys,
81
+ }
82
+
83
+ /**
84
+ * Network menu hook
85
+ */
86
+ function network_settings_menu(){
87
+ add_submenu_page(
88
+ 'settings.php',
89
+ __( 'reCaptcha Settings' , 'wp-recaptcha-integration' ),
90
+ __( 'reCaptcha' , 'wp-recaptcha-integration' ),
91
+ 'manage_network', 'racaptcha-settings',
92
+ array(&$this , 'network_settings_page' ) );
93
+ }
94
+
95
+ /**
96
+ * Network Settings page
97
+ */
98
+ function network_settings_page() {
99
+ // h1, form, nonce, sanitize, process
100
+ ?><div class="wrap"><?php
101
+ ?><h2><?php _e( 'reCaptcha Settings' , 'wp-recaptcha-integration' ) ?></h2><?php
102
+ ?><form method="post"><?php
103
+ wp_nonce_field( 'recaptcha-network-settings' );
104
+ do_settings_sections('recaptcha');
105
+ submit_button();
106
+ ?></form><?php
107
+ ?></div><?php
108
+ }
109
+
110
+
111
+
112
+ /**
113
+ * Update option hook. Remove url params for redirect
114
+ *
115
+ * @param new updated option value
116
+ * @param old old option value
117
+ */
118
+ function update_option_recaptcha_apikey( $new , $old ){
119
+ add_filter( 'wp_redirect' , array( &$this , 'remove_new_apikey_url' ) );
120
+ return $new;
121
+ }
122
+ /**
123
+ * Add option hook. See update_option_recaptcha_apikey()
124
+ *
125
+ * @param option option name
126
+ * @param value option value
127
+ */
128
+ function add_option_recaptcha_apikey( $option , $value ){
129
+ if ( in_array( $option , array('recaptcha_publickey','recaptcha_privatekey') ) )
130
+ add_filter( 'wp_redirect' , array( &$this , 'remove_new_apikey_url' ) );
131
+ }
132
+
133
+ /**
134
+ * Removes Update api key url params
135
+ * @param url URL
136
+ * @return string URL without params removed
137
+ */
138
+ function remove_new_apikey_url( $url = null ) {
139
+ return remove_query_arg( array('_wpnonce' , 'recaptcha-action' , 'settings-updated' ) , $url );
140
+ }
141
+
142
+ /**
143
+ * Admin Notices hook to show up when the api keys heve not been entered.
144
+ */
145
+ function api_key_notice() {
146
+ ?><div class="notice error above-h1"><p><?php
147
+ printf(
148
+ __( '<strong>reCaptcha needs your attention:</strong> To make it work You need to enter an api key. <br />You can do so at the <a href="%s">reCaptcha settings page</a>.' , 'wp-recaptcha-integration' ),
149
+ admin_url( add_query_arg( 'page' , 'recaptcha' , 'options-general.php' ) )
150
+ );
151
+ ?></p></div><?php
152
+ }
153
+
154
+ /**
155
+ * admin init hook. Setup settings according.
156
+ */
157
+ function admin_init( ) {
158
+
159
+ $has_api_key = WP_reCaptcha::instance()->has_api_key();
160
+ if ( ! $has_api_key && current_user_can( 'manage_options' ) ) {
161
+ add_action('admin_notices',array( &$this , 'api_key_notice'));
162
+ }
163
+
164
+ $this->enter_api_key = ! $has_api_key || ( isset($_REQUEST['recaptcha-action']) && $_REQUEST['recaptcha-action'] == 'recaptcha-set-api-key');
165
+ if ( $this->enter_api_key ) {
166
+ // no API Key. Let the user enter it.
167
+ register_setting( 'recaptcha_options', 'recaptcha_publickey' , 'trim' );
168
+ register_setting( 'recaptcha_options', 'recaptcha_privatekey' , 'trim' );
169
+ add_settings_field('recaptcha_publickey', __('Public Key','wp-recaptcha-integration'), array(&$this,'secret_input_text'), 'recaptcha', 'recaptcha_apikey' , array('name'=>'recaptcha_publickey') );
170
+ add_settings_field('recaptcha_privatekey', __('Private Key','wp-recaptcha-integration'), array(&$this,'secret_input_text'), 'recaptcha', 'recaptcha_apikey', array('name'=>'recaptcha_privatekey'));
171
+ add_settings_section('recaptcha_apikey', __( 'Connecting' , 'wp-recaptcha-integration' ), array(&$this,'explain_apikey'), 'recaptcha');
172
+ if ( $has_api_key ) {
173
+ add_settings_field('cancel', '' , array(&$this,'cancel_enter_api_key'), 'recaptcha', 'recaptcha_apikey' );
174
+ }
175
+ } else {
176
+ // API Key. Add test tool.
177
+ add_settings_section('recaptcha_apikey', __( 'Connecting' , 'wp-recaptcha-integration' ), array(&$this,'explain_apikey'), 'recaptcha');
178
+ add_action('wp_ajax_recaptcha-test-api-key' , array( &$this , 'ajax_test_api_key' ) );
179
+ add_action('wp_ajax_recaptcha-test-verification' , array( &$this , 'ajax_test_api_key_verification' ) );
180
+ }
181
+
182
+ if ( $has_api_key ) {
183
+ if ( ! WP_reCaptcha::is_network_activated() || ! is_network_admin() ) {
184
+ register_setting( 'recaptcha_options', 'recaptcha_flavor' , array( &$this , 'sanitize_flavor' ) );
185
+ register_setting( 'recaptcha_options', 'recaptcha_theme' , array( &$this , 'sanitize_theme' ) );
186
+
187
+ add_settings_field('recaptcha_flavor', __('Flavor','wp-recaptcha-integration'),
188
+ array(&$this,'input_radio'), 'recaptcha', 'recaptcha_options',
189
+ array(
190
+ 'name' => 'recaptcha_flavor',
191
+ 'items' => array(
192
+ array(
193
+ 'value' => 'grecaptcha',
194
+ 'label' => __( 'No Captcha where you just click a button' , 'wp-recaptcha-integration' ),
195
+ ),
196
+ array(
197
+ 'value' => 'recaptcha',
198
+ 'label' => __( 'Old style reCAPTCHA where you type some cryptic text' , 'wp-recaptcha-integration' ),
199
+ ),
200
+ ),
201
+ ) );
202
+
203
+ add_settings_field('recaptcha_theme', __('Theme','wp-recaptcha-integration'), array(&$this,'select_theme'), 'recaptcha', 'recaptcha_options');
204
+
205
+
206
+ }
207
+ if ( ! WP_reCaptcha::is_network_activated() || is_network_admin() ) {
208
+ register_setting( 'recaptcha_options', 'recaptcha_enable_comments' , 'intval');
209
+ register_setting( 'recaptcha_options', 'recaptcha_enable_signup', 'intval' );
210
+ register_setting( 'recaptcha_options', 'recaptcha_enable_login' , 'intval');
211
+ register_setting( 'recaptcha_options', 'recaptcha_enable_lostpw' , 'intval');
212
+ register_setting( 'recaptcha_options', 'recaptcha_disable_for_known_users' , 'intval');
213
+
214
+ add_settings_field('recaptcha_enable_comments', __('Protect Comments','wp-recaptcha-integration'),
215
+ array(&$this,'input_checkbox'), 'recaptcha', 'recaptcha_options' ,
216
+ array('name'=>'recaptcha_enable_comments','label'=>__( 'Protect comment forms with recaptcha.' ,'wp-recaptcha-integration' ) )
217
+ );
218
+
219
+ add_settings_field('recaptcha_enable_signup', __('Protect Signup','wp-recaptcha-integration'),
220
+ array(&$this,'input_checkbox'), 'recaptcha', 'recaptcha_options',
221
+ array('name'=>'recaptcha_enable_signup','label'=>__( 'Protect signup form with recaptcha.','wp-recaptcha-integration' ) )
222
+ );
223
+
224
+ add_settings_field('recaptcha_enable_login', __('Protect Login','wp-recaptcha-integration'),
225
+ array(&$this,'input_checkbox'), 'recaptcha', 'recaptcha_options' ,
226
+ array('name'=>'recaptcha_enable_login','label'=>__( 'Protect Login form with recaptcha.','wp-recaptcha-integration' ))
227
+ );
228
+
229
+ add_settings_field('recaptcha_enable_lostpw', __('Protect Lost Password','wp-recaptcha-integration'),
230
+ array(&$this,'input_checkbox'), 'recaptcha', 'recaptcha_options' ,
231
+ array('name'=>'recaptcha_enable_lostpw','label'=>__( 'Protect Lost Password form with recaptcha.','wp-recaptcha-integration' ))
232
+ );
233
+
234
+ add_settings_field('recaptcha_disable_for_known_users', __('Disable for known users','wp-recaptcha-integration'),
235
+ array(&$this,'input_checkbox'), 'recaptcha', 'recaptcha_options' ,
236
+ array('name'=>'recaptcha_disable_for_known_users','label'=>__( 'Disable reCaptcha verification for logged in users.','wp-recaptcha-integration' ))
237
+ );
238
+ }
239
+ add_settings_section('recaptcha_options', __( 'Features' , 'wp-recaptcha-integration' ), '__return_false', 'recaptcha');
240
+
241
+ if ( ! WP_reCaptcha::instance()->get_option( 'recaptcha_publickey' ) || ! WP_reCaptcha::instance()->get_option( 'recaptcha_privatekey' ) )
242
+ add_settings_error('recaptcha',1,__('Please configure the public and private key. <a href="http://www.google.com/recaptcha/whyrecaptcha">What are you trying to tell me?</a>','wp-recaptcha-integration'),'updated');
243
+ }
244
+ }
245
+
246
+ /**
247
+ * Intro text for the api key setting
248
+ */
249
+ public function explain_apikey( ) {
250
+ if ( $this->enter_api_key ) {
251
+ ?><p class="description"><?php
252
+ $info_url = 'https://developers.google.com/recaptcha/intro';
253
+ $admin_url = 'https://www.google.com/recaptcha/admin';
254
+ printf(
255
+ __( 'Please register your blog through the <a href="%s">Google reCAPTCHA admin page</a> and enter the public and private key in the fields below. <a href="%s">What is this all about</a>', 'wp-recaptcha-integration' ) ,
256
+ $admin_url , $info_url
257
+ );
258
+ ?></p><?php
259
+ ?><input type="hidden" name="recaptcha-action" value="recaptcha-set-api-key" /><?php
260
+ } else {
261
+ ?><div class="recaptcha-explain"><?php
262
+ ?><p class="description"><?php
263
+ _e( 'You already entered an API Key. Use the button below to enter it again.','wp-recaptcha-integration');
264
+ ?></p><?php
265
+ $action = 'recaptcha-set-api-key';
266
+ $nonce = wp_create_nonce( $action );
267
+ $new_url = add_query_arg( array('_wpnonce' => $nonce , 'recaptcha-action' => $action ) );
268
+
269
+ $action = 'recaptcha-test-api-key';
270
+ $nonce = wp_create_nonce( $action );
271
+ $test_url = add_query_arg( array('_wpnonce' => $nonce , 'action' => $action ) , admin_url( 'admin-ajax.php' ) );
272
+
273
+ ?><p class="submit"><?php
274
+ ?><a class="button" href="<?php echo $new_url ?>"><?php _e('New API Key' , 'wp-recaptcha-integration') ?></a><?php
275
+ ?><a id="test-api-key" class="button" href="<?php echo $test_url ?>"><?php _e('Test API Key' , 'wp-recaptcha-integration') ?></a><?php
276
+ ?></p><?php
277
+ ?></div><?php
278
+ }
279
+ }
280
+
281
+
282
+ /**
283
+ * Test api key ajax response.
284
+ * Returns reCaptcha HTML
285
+ */
286
+ public function ajax_test_api_key() {
287
+ if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'] , $_REQUEST['action'] ) ) {
288
+ header('Content-Type: text/html');
289
+ WP_reCaptcha::instance()->recaptcha_script( 'grecaptcha' );
290
+ WP_reCaptcha::instance()->print_recaptcha_html( 'grecaptcha' );
291
+ $action = 'recaptcha-test-verification';
292
+ $nonce = wp_create_nonce( $action );
293
+ ?><input type="hidden" name="<?php echo $action ?>-nonce" value="<?php echo $nonce ?>" /><?php
294
+ ?><button id="<?php echo $action ?>" name="action" class="button-primary" value="<?php echo $action ?>"><?php _e('Test verfication','wp-recaptcha-integration') ?></button><?php
295
+ }
296
+ exit(0);
297
+ }
298
+ /**
299
+ * Test api key ajax response.
300
+ * checks the verification process and shows an error on fail.
301
+ */
302
+ public function ajax_test_api_key_verification() {
303
+ if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'] , $_REQUEST['action'] ) ) {
304
+ header('Content-Type: text/html');
305
+ if ( ! WP_reCaptcha::instance()->recaptcha_check( 'grecaptcha' ) ) {
306
+ $errs = array(
307
+ 'missing-input-secret' => __('The secret Key is missing.','wp-recaptcha-integration'),
308
+ 'invalid-input-secret' => __('The secret Key is invalid. You better check your domain configuration and enter it again.','wp-recaptcha-integration'),
309
+ 'missing-input-response' => __('The user response was missing ','wp-recaptcha-integration'),
310
+ 'invalid-input-response' => __('Invalid user response','wp-recaptcha-integration'),
311
+ );
312
+ $result = WP_reCaptcha::instance()->get_last_result();
313
+ if ( isset( $result['error-codes'] ) ) {
314
+ foreach ( $result['error-codes'] as $err ) {
315
+ ?><div class="error"><p><?php echo $errs[$err]; ?></p></div><?php
316
+ }
317
+ }
318
+ } else {
319
+ ?><div class="updated"><p><?php _e('Works! All good!','wp-recaptcha-integration') ?></p></div><?php
320
+ }
321
+ }
322
+ exit(0);
323
+ }
324
+
325
+ /**
326
+ * Link for canceling api key entering
327
+ * checks the verification process and shows an error on fail.
328
+ */
329
+ public function cancel_enter_api_key() {
330
+ $url = $this->remove_new_apikey_url( );
331
+ ?><a class="button" href="<?php echo $url ?>"><?php _e( 'Cancel' ) ?></a><?php
332
+ }
333
+
334
+ /**
335
+ * Radio buttons
336
+ *
337
+ * @param args array(
338
+ * 'name' => name of the input field,
339
+ * 'items' => array(
340
+ * array(
341
+ * 'value' => '', // the radio button value, must match an option name
342
+ * 'label' => '', // the button label
343
+ * ),
344
+ * ...
345
+ * )
346
+ * )
347
+ */
348
+ public function input_radio( $args ) {
349
+ extract($args); // name, items
350
+ $option = WP_reCaptcha::instance()->get_option( $name );
351
+ foreach ( $items as $item ) {
352
+ extract( $item ); // value, label
353
+ ?><label for="<?php echo "$name-$value" ?>"><?php
354
+ ?><input id="<?php echo "$name-$value" ?>" type="radio" name="<?php echo $name ?>" value="<?php echo $value ?>" <?php checked($value,$option,true) ?> />
355
+ <?php
356
+ echo $label;
357
+ ?></label><br /><?php
358
+ }
359
+ }
360
+
361
+ /**
362
+ * A Checkbox
363
+ *
364
+ * @param args array(
365
+ * 'name' => '', // checkbox field name, must match an option name
366
+ * 'label' => '', // button label
367
+ * )
368
+ */
369
+ public function input_checkbox($args) {
370
+ extract($args);
371
+ $value = WP_reCaptcha::instance()->get_option( $name );
372
+ ?><label for="<?php echo $name ?>"><?php
373
+ ?><input type="hidden" name="<?php echo $name ?>" value="0" /><?php
374
+ ?><input id="<?php echo $name ?>" type="checkbox" name="<?php echo $name ?>" value="1" <?php checked($value,1,true) ?> />
375
+ <?php
376
+ echo $label;
377
+ ?></label><?php
378
+ }
379
+ /**
380
+ * A Text field.
381
+ * Used for api key input.
382
+ *
383
+ * @param args array(
384
+ * 'name' => checkbox field name, must match an option name
385
+ * )
386
+ */
387
+ public function secret_input_text( $args ) {
388
+ extract( $args );
389
+ $value = WP_reCaptcha::instance()->get_option( $name );
390
+ ?><input type="text" class="regular-text ltr" name="<?php echo $name ?>" value="<?php //echo $value ?>" /><?php
391
+ }
392
+
393
+ /**
394
+ * Selector for recaptcha theme
395
+ */
396
+ public function select_theme() {
397
+ $option_name = 'recaptcha_theme';
398
+
399
+ $themes = array(
400
+ 'light' => array(
401
+ 'label' => __('Light','wp-recaptcha-integration') ,
402
+ 'flavor' => 'grecaptcha',
403
+ ),
404
+ 'dark' => array(
405
+ 'label' => __('Dark','wp-recaptcha-integration') ,
406
+ 'flavor' => 'grecaptcha',
407
+ ),
408
+
409
+ 'red' => array(
410
+ 'label' => __('Red','wp-recaptcha-integration') ,
411
+ 'flavor' => 'recaptcha',
412
+ ),
413
+ 'white' => array(
414
+ 'label' => __('White','wp-recaptcha-integration') ,
415
+ 'flavor' => 'recaptcha',
416
+ ),
417
+ 'blackglass' => array(
418
+ 'label' => __('Black Glass','wp-recaptcha-integration') ,
419
+ 'flavor' => 'recaptcha',
420
+ ),
421
+ 'clean' => array(
422
+ 'label' => __('Clean','wp-recaptcha-integration') ,
423
+ 'flavor' => 'recaptcha',
424
+ ),
425
+ 'custom' => array(
426
+ 'label' => __('Custom','wp-recaptcha-integration') ,
427
+ 'flavor' => 'recaptcha',
428
+ ),
429
+ );
430
+
431
+ $option_theme = WP_reCaptcha::instance()->get_option($option_name);
432
+ $option_flavor = WP_reCaptcha::instance()->get_option( 'recaptcha_flavor' );
433
+
434
+ ?><div class="recaptcha-select-theme flavor-<?php echo $option_flavor ?>"><?php
435
+
436
+ foreach ( $themes as $value => $theme ) {
437
+ extract( $theme ); // label, flavor
438
+ ?><div class="theme-item flavor-<?php echo $flavor ?>"><?php
439
+ ?><input <?php checked($value,$option_theme,true); ?> id="<?php echo "$option_name-$value" ?>" type="radio" name="<?php echo $option_name ?>" value="<?php echo $value ?>" /><?php
440
+ ?><label for="<?php echo "$option_name-$value" ?>"><?php
441
+ ?><span class="title"><?php
442
+ echo $label;
443
+ ?></span><?php
444
+ if ( $value == 'custom' ) {
445
+ ?><span class="visual"><?php
446
+ _e( 'Unstyled HTML to apply your own Stylesheets.' , 'wp-recaptcha-integration' );
447
+ ?></span><?php
448
+ } else {
449
+ $src = plugins_url( "images/{$flavor}-theme-{$value}.png" , dirname(__FILE__));
450
+ printf( '<img src="%s" alt="%s" />' , $src , $label );
451
+ }
452
+ ?></label><?php
453
+ ?></div><?php
454
+
455
+ }
456
+ ?></div><?php
457
+ ?></div><?php
458
+ }
459
+ /**
460
+ * Check valid recaptcha theme, check if theme fits to flavor
461
+ */
462
+ public function sanitize_theme( $theme ) {
463
+ $themes_available = array(
464
+ 'recaptcha' => array( 'white','red','blackglass','clean','custom' ),
465
+ 'grecaptcha' => array( 'light','dark' ),
466
+ );
467
+ $flavor = WP_reCaptcha::instance()->get_option('recaptcha_flavor');
468
+
469
+ if ( isset($themes_available[$flavor] ) && in_array($theme,$themes_available[$flavor]) )
470
+ return $theme;
471
+ else if ( isset($themes_available[$flavor] ) )
472
+ return $themes_available[$flavor][0];
473
+ return 'light';
474
+ }
475
+
476
+ /**
477
+ * Check valid flavor
478
+ */
479
+ public function sanitize_flavor( $flavor ) {
480
+ if ( in_array($flavor,array('recaptcha','grecaptcha')) )
481
+ return $flavor;
482
+ return 'grecaptcha';
483
+ }
484
+
485
+ /**
486
+ * Admin menu hook, adds blogs local options page
487
+ */
488
+ public function add_options_page() {
489
+ $page_slug = add_options_page(
490
+ __('ReCaptcha','wp-recaptcha-integration'), __('ReCaptcha','wp-recaptcha-integration'),
491
+ 'manage_options', 'recaptcha',
492
+ array(&$this,'render_options_page')
493
+ );
494
+
495
+ add_action( "load-$page_slug" , array( &$this , 'enqueue_styles' ) );
496
+ }
497
+
498
+ /**
499
+ * Enqueue script and css for options page.
500
+ */
501
+ public function enqueue_styles() {
502
+ wp_enqueue_style( 'recaptcha-options' , plugins_url( "css/recaptcha-options.css" , dirname(__FILE__)) );
503
+ wp_enqueue_script( 'recaptcha-options' , plugins_url( "js/recaptcha-options.js" , dirname(__FILE__)) , array( 'jquery' ) );
504
+ remove_action('admin_notices',array( &$this , 'api_key_notice'));
505
+ }
506
+ /**
507
+ * Enqueue script and css for options page.
508
+ */
509
+ public function render_options_page() {
510
+ ?><div class="wrap"><?php
511
+ ?><h2><?php /*icon*/
512
+ _e('Settings');
513
+ echo ' › ';
514
+ _e( 'ReCaptcha' , 'wp-recaptcha-integration' );
515
+ ?></h2><?php
516
+ /* ?><p><?php _e( '...' , 'googlefont' ); ?></p><?php */
517
+ ?><form action="options.php" method="post"><?php
518
+ settings_fields( 'recaptcha_options' );
519
+ do_settings_sections( 'recaptcha' );
520
+ submit_button();
521
+ ?></form><?php
522
+ ?></div><?php
523
+ }
524
+
525
+ }
526
+
527
+
528
+ WP_reCaptcha_Options::instance();
529
+
inc/contact_form_7_recaptcha.php CHANGED
@@ -9,13 +9,13 @@ add_action( 'wpcf7_init', 'wpcf7_add_shortcode_recaptcha' );
9
 
10
 
11
  function wpcf7_recaptcha_shortcode_handler( $tag ) {
12
- if ( ! WordPress_reCaptcha::instance()->is_required() )
13
  return apply_filters( 'recaptcha_disabled_html' ,'');
14
  $tag = new WPCF7_Shortcode( $tag );
15
  if ( empty( $tag->name ) )
16
  return '';
17
 
18
- $recaptcha_html = WordPress_reCaptcha::instance()->recaptcha_html();
19
  $validation_error = wpcf7_get_validation_error( $tag->name );
20
 
21
  $html = sprintf(
@@ -62,13 +62,13 @@ function wpcf7_recaptcha_settings_callback( $contact_form ) {
62
 
63
 
64
  function wpcf7_recaptcha_validation_filter( $result, $tag ) {
65
- if ( ! WordPress_reCaptcha::instance()->is_required() )
66
  return $result;
67
 
68
  $tag = new WPCF7_Shortcode( $tag );
69
  $name = $tag->name;
70
 
71
- if ( ! WordPress_reCaptcha::instance()->recaptcha_check() ) {
72
  $result['valid'] = false;
73
  $result['reason'][$name] = __("The Captcha didn’t verify.",'wp-recaptcha-integration');
74
  }
9
 
10
 
11
  function wpcf7_recaptcha_shortcode_handler( $tag ) {
12
+ if ( ! WP_reCaptcha::instance()->is_required() )
13
  return apply_filters( 'recaptcha_disabled_html' ,'');
14
  $tag = new WPCF7_Shortcode( $tag );
15
  if ( empty( $tag->name ) )
16
  return '';
17
 
18
+ $recaptcha_html = WP_reCaptcha::instance()->recaptcha_html();
19
  $validation_error = wpcf7_get_validation_error( $tag->name );
20
 
21
  $html = sprintf(
62
 
63
 
64
  function wpcf7_recaptcha_validation_filter( $result, $tag ) {
65
+ if ( ! WP_reCaptcha::instance()->is_required() )
66
  return $result;
67
 
68
  $tag = new WPCF7_Shortcode( $tag );
69
  $name = $tag->name;
70
 
71
+ if ( ! WP_reCaptcha::instance()->recaptcha_check() ) {
72
  $result['valid'] = false;
73
  $result['reason'][$name] = __("The Captcha didn’t verify.",'wp-recaptcha-integration');
74
  }
inc/ninja_forms_field_recaptcha.php CHANGED
@@ -34,30 +34,32 @@ function ninja_forms_register_field_recaptcha(){
34
  }
35
  if ( function_exists('ninja_forms_register_field') ) {
36
  add_action('init', 'ninja_forms_register_field_recaptcha');
37
- add_action('wp_footer','ninja_forms_recaptcha_script');
38
  add_filter('ninja_forms_field','ninja_forms_recaptcha_field_data',10,2);
39
  }
40
 
41
  function ninja_forms_recaptcha_field_data( $data, $field_id ) {
42
  $field_row = ninja_forms_get_field_by_id($field_id);
43
  if ( $field_row['type'] == '_recaptcha' )
44
- $data['show_field'] = WordPress_reCaptcha::instance()->is_required();
45
  return $data;
46
  }
47
 
48
  function ninja_forms_recaptcha_script($id) {
49
  // print script
50
- $html = '<script type="text/javascript">
51
- jQuery(document).on("submitResponse.default", function(e, response){
52
- Recaptcha.reload();
53
- });
54
- </script>';
55
- echo $html;
 
 
56
  }
57
 
58
  function ninja_forms_field_recaptcha_display($field_id, $data){
59
- if ( WordPress_reCaptcha::instance()->is_required() )
60
- WordPress_reCaptcha::instance()->print_recaptcha_html();
61
  else
62
  echo apply_filters( 'recaptcha_disabled_html' ,'');
63
  }
@@ -72,9 +74,9 @@ function ninja_forms_field_recaptcha_pre_process( $field_id, $user_value ){
72
  $form_id = $form_row['id'];
73
 
74
 
75
- $require_recaptcha = WordPress_reCaptcha::instance()->is_required();
76
 
77
- if ( $ninja_forms_processing->get_action() != 'save' && $ninja_forms_processing->get_action() != 'mp_save' && $require_recaptcha && ! WordPress_reCaptcha::instance()->recaptcha_check() ){
78
  $ninja_forms_processing->add_error('recaptcha-general', $recaptcha_error, 'general');
79
  $ninja_forms_processing->add_error('recaptcha-'.$field_id, $recaptcha_error, $field_id);
80
  }
34
  }
35
  if ( function_exists('ninja_forms_register_field') ) {
36
  add_action('init', 'ninja_forms_register_field_recaptcha');
37
+ add_action('wp_footer','ninja_forms_recaptcha_script',9999);
38
  add_filter('ninja_forms_field','ninja_forms_recaptcha_field_data',10,2);
39
  }
40
 
41
  function ninja_forms_recaptcha_field_data( $data, $field_id ) {
42
  $field_row = ninja_forms_get_field_by_id($field_id);
43
  if ( $field_row['type'] == '_recaptcha' )
44
+ $data['show_field'] = WP_reCaptcha::instance()->is_required();
45
  return $data;
46
  }
47
 
48
  function ninja_forms_recaptcha_script($id) {
49
  // print script
50
+ if ( 'recaptcha' == WP_reCaptcha::instance()->get_option( 'recaptcha_flavor' ) ) {
51
+ $html = '<script type="text/javascript">
52
+ jQuery(document).on("submitResponse.default", function(e, response){
53
+ Recaptcha.reload();
54
+ });
55
+ </script>';
56
+ echo $html;
57
+ }
58
  }
59
 
60
  function ninja_forms_field_recaptcha_display($field_id, $data){
61
+ if ( WP_reCaptcha::instance()->is_required() )
62
+ WP_reCaptcha::instance()->print_recaptcha_html();
63
  else
64
  echo apply_filters( 'recaptcha_disabled_html' ,'');
65
  }
74
  $form_id = $form_row['id'];
75
 
76
 
77
+ $require_recaptcha = WP_reCaptcha::instance()->is_required();
78
 
79
+ if ( $ninja_forms_processing->get_action() != 'save' && $ninja_forms_processing->get_action() != 'mp_save' && $require_recaptcha && ! WP_reCaptcha::instance()->recaptcha_check() ){
80
  $ninja_forms_processing->add_error('recaptcha-general', $recaptcha_error, 'general');
81
  $ninja_forms_processing->add_error('recaptcha-'.$field_id, $recaptcha_error, $field_id);
82
  }
inc/recaptcha-options.php DELETED
@@ -1,335 +0,0 @@
1
- <?php
2
-
3
-
4
-
5
- class WordPress_reCaptcha_Options {
6
- private $enter_api_key;
7
- /**
8
- * Holding the singleton instance
9
- */
10
- private static $_instance = null;
11
-
12
- /**
13
- * @return WordPress_reCaptcha_Options The options manager instance
14
- */
15
- public static function instance(){
16
- if ( is_null( self::$_instance ) )
17
- self::$_instance = new self();
18
- return self::$_instance;
19
- }
20
-
21
- /**
22
- * Prevent from creating more than one instance
23
- */
24
- private function __clone() {
25
- }
26
- /**
27
- * Prevent from creating more than one instance
28
- */
29
- private function __construct() {
30
- add_action('admin_init', array(&$this,'admin_init') );
31
- add_action('admin_menu', array(&$this,'add_options_page') );
32
-
33
- add_action( 'pre_update_option_recaptcha_publickey' , array( &$this , 'update_option_recaptcha_apikey' ) , 10 , 2 );
34
- add_action( 'pre_update_option_recaptcha_privatekey' , array( &$this , 'update_option_recaptcha_apikey' ) , 10 , 2 );
35
- add_action( 'add_option_recaptcha_publickey' , array( &$this , 'add_option_recaptcha_apikey' ) , 10 , 2 );
36
- add_action( 'add_option_recaptcha_privatekey' , array( &$this , 'add_option_recaptcha_apikey' ) , 10 , 2 );
37
- }
38
-
39
- function update_option_recaptcha_apikey( $new , $old ){
40
- add_filter( 'wp_redirect' , array( &$this , 'remove_new_apikey_url' ) );
41
- return $new;
42
- }
43
- function add_option_recaptcha_apikey( $option , $value ){
44
- if ( in_array( $option , array('recaptcha_publickey','recaptcha_privatekey') ) )
45
- add_filter( 'wp_redirect' , array( &$this , 'remove_new_apikey_url' ) );
46
- }
47
-
48
- function remove_new_apikey_url( $url = null ) {
49
- return remove_query_arg( array('_wpnonce' , 'recaptcha-action' , 'settings-updated' ) , $url );
50
- }
51
-
52
- function api_key_notice() {
53
- ?><div class="notice error above-h1"><p><?php
54
- printf(
55
- __( '<strong>reCaptcha needs your attention:</strong> To make it work You need to enter an api key. <br />You can do so at the <a href="%s">reCaptcha settings page</a>.' , 'wp-recaptcha-integration' ),
56
- admin_url( add_query_arg( 'page' , 'recaptcha' , 'options-general.php' ) )
57
- );
58
- ?></p></div><?php
59
- }
60
- function admin_init( ) {
61
-
62
- $has_api_key = WordPress_reCaptcha::instance()->has_api_key();
63
- if ( ! $has_api_key && current_user_can( 'manage_options' ) ) {
64
- add_action('admin_notices',array( &$this , 'api_key_notice'));
65
- }
66
-
67
- $this->enter_api_key = ! $has_api_key || ( isset($_REQUEST['recaptcha-action']) && $_REQUEST['recaptcha-action'] == 'recaptcha-set-api-key');
68
- if ( $this->enter_api_key ) {
69
- // no API Key. Let the user enter it.
70
- register_setting( 'recaptcha_options', 'recaptcha_publickey' );
71
- register_setting( 'recaptcha_options', 'recaptcha_privatekey' );
72
- add_settings_field('recaptcha_publickey', __('Public Key','wp-recaptcha-integration'), array(&$this,'input_text'), 'recaptcha', 'recaptcha_apikey' , array('name'=>'recaptcha_publickey') );
73
- add_settings_field('recaptcha_privatekey', __('Private Key','wp-recaptcha-integration'), array(&$this,'input_text'), 'recaptcha', 'recaptcha_apikey', array('name'=>'recaptcha_privatekey'));
74
- add_settings_section('recaptcha_apikey', __( 'Connecting' , 'wp-recaptcha-integration' ), array(&$this,'explain_apikey'), 'recaptcha');
75
- if ( $has_api_key ) {
76
- add_settings_field('cancel', '' , array(&$this,'cancel_enter_api_key'), 'recaptcha', 'recaptcha_apikey' );
77
- }
78
- } else if ( @$nonce_valid === false) {
79
- wp_die('Security Check');
80
- } else {
81
- // API Key. Add test tool.
82
- add_settings_section('recaptcha_apikey', __( 'Connecting' , 'wp-recaptcha-integration' ), array(&$this,'explain_apikey'), 'recaptcha');
83
- add_action('wp_ajax_recaptcha-test-api-key' , array( &$this , 'ajax_test_api_key' ) );
84
- }
85
-
86
- if ( $has_api_key ) {
87
- register_setting( 'recaptcha_options', 'recaptcha_flavor' , array( &$this , 'sanitize_flavor' ) );
88
- register_setting( 'recaptcha_options', 'recaptcha_theme' , array( &$this , 'sanitize_theme' ) );
89
- register_setting( 'recaptcha_options', 'recaptcha_enable_comments' , 'intval');
90
- register_setting( 'recaptcha_options', 'recaptcha_enable_signup', 'intval' );
91
- register_setting( 'recaptcha_options', 'recaptcha_enable_login' , 'intval');
92
- register_setting( 'recaptcha_options', 'recaptcha_enable_lostpw' , 'intval');
93
- register_setting( 'recaptcha_options', 'recaptcha_disable_for_known_users' , 'intval');
94
-
95
- add_settings_section('recaptcha_options', __( 'Features' , 'wp-recaptcha-integration' ), '__return_false', 'recaptcha');
96
-
97
- add_settings_field('recaptcha_flavor', __('Flavor','wp-recaptcha-integration'),
98
- array(&$this,'input_radio'), 'recaptcha', 'recaptcha_options',
99
- array(
100
- 'name' => 'recaptcha_flavor',
101
- 'items' => array(
102
- array(
103
- 'value' => 'grecaptcha',
104
- 'label' => __( 'No Captcha where you just click a button' , 'wp-recaptcha-integration' ),
105
- ),
106
- array(
107
- 'value' => 'recaptcha',
108
- 'label' => __( 'Old style reCAPTCHA where you type some cryptic text' , 'wp-recaptcha-integration' ),
109
- ),
110
- ),
111
- ) );
112
-
113
- add_settings_field('recaptcha_theme', __('Theme','wp-recaptcha-integration'), array(&$this,'select_theme'), 'recaptcha', 'recaptcha_options');
114
-
115
-
116
- add_settings_field('recaptcha_enable_comments', __('Protect Comments','wp-recaptcha-integration'),
117
- array(&$this,'input_checkbox'), 'recaptcha', 'recaptcha_options' ,
118
- array('name'=>'recaptcha_enable_comments','label'=>__( 'Protect comment forms with recaptcha.' ,'wp-recaptcha-integration' ) )
119
- );
120
-
121
- add_settings_field('recaptcha_enable_signup', __('Protect Signup','wp-recaptcha-integration'),
122
- array(&$this,'input_checkbox'), 'recaptcha', 'recaptcha_options',
123
- array('name'=>'recaptcha_enable_signup','label'=>__( 'Protect signup form with recaptcha.','wp-recaptcha-integration' ) )
124
- );
125
-
126
- add_settings_field('recaptcha_enable_login', __('Protect Login','wp-recaptcha-integration'),
127
- array(&$this,'input_checkbox'), 'recaptcha', 'recaptcha_options' ,
128
- array('name'=>'recaptcha_enable_login','label'=>__( 'Protect Login form with recaptcha.','wp-recaptcha-integration' ))
129
- );
130
-
131
- add_settings_field('recaptcha_enable_lostpw', __('Protect Lost Password','wp-recaptcha-integration'),
132
- array(&$this,'input_checkbox'), 'recaptcha', 'recaptcha_options' ,
133
- array('name'=>'recaptcha_enable_lostpw','label'=>__( 'Protect Lost Password form with recaptcha.','wp-recaptcha-integration' ))
134
- );
135
-
136
- add_settings_field('recaptcha_disable_for_known_users', __('Disable for known users','wp-recaptcha-integration'),
137
- array(&$this,'input_checkbox'), 'recaptcha', 'recaptcha_options' ,
138
- array('name'=>'recaptcha_disable_for_known_users','label'=>__( 'Disable reCaptcha verification for logged in users.','wp-recaptcha-integration' ))
139
- );
140
-
141
- if ( ! get_option( 'recaptcha_publickey' ) || ! get_option( 'recaptcha_privatekey' ) )
142
- add_settings_error('recaptcha',1,__('Please configure the public and private key. <a href="http://www.google.com/recaptcha/whyrecaptcha">What are you trying to tell me?</a>','wp-recaptcha-integration'),'updated');
143
- }
144
- }
145
-
146
- public function explain_apikey( ) {
147
- if ( $this->enter_api_key ) {
148
- ?><p class="description"><?php
149
- $info_url = 'https://developers.google.com/recaptcha/intro';
150
- $admin_url = 'https://www.google.com/recaptcha/admin';
151
- printf(
152
- __( 'Please register your blog through the <a href="%s">Google reCAPTCHA admin page</a> and enter the public and private key in the fields below. <a href="%s">What is this all about</a>', 'wp-recaptcha-integration' ) ,
153
- $admin_url , $info_url
154
- );
155
- ?></p><?php
156
- ?><input type="hidden" name="recaptcha-action" value="recaptcha-set-api-key" /><?php
157
- } else {
158
- ?><div class="recaptcha-explain"><?php
159
- ?><p class="description"><?php
160
- _e( 'You already entered an API Key. Use the button below to enter it again.','wp-recaptcha-integration');
161
- ?></p><?php
162
- $action = 'recaptcha-set-api-key';
163
- $nonce = wp_create_nonce( $action );
164
- $new_url = add_query_arg( array('_wpnonce' => $nonce , 'recaptcha-action' => $action ) );
165
-
166
- $action = 'recaptcha-test-api-key';
167
- $nonce = wp_create_nonce( $action );
168
- $test_url = add_query_arg( array('_wpnonce' => $nonce , 'action' => $action ) , admin_url( 'admin-ajax.php' ) );
169
-
170
- ?><p class="submit"><?php
171
- ?><a class="button" href="<?php echo $new_url ?>"><?php _e('New API Key' , 'wp-recaptcha-integration') ?></a><?php
172
- ?><a id="test-api-key" class="button" href="<?php echo $test_url ?>"><?php _e('Test API Key' , 'wp-recaptcha-integration') ?></a><?php
173
- ?></p><?php
174
- ?></div><?php
175
- }
176
- }
177
-
178
- public function ajax_test_api_key() {
179
- if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'] , $_REQUEST['action'] ) ) {
180
- header('Content-Type: text/html');
181
- WordPress_reCaptcha::instance()->recaptcha_script( 'grecaptcha' );
182
- WordPress_reCaptcha::instance()->print_recaptcha_html( 'grecaptcha' );
183
- }
184
- exit(0);
185
- }
186
-
187
- public function cancel_enter_api_key(){
188
- $url = $this->remove_new_apikey_url( );
189
- // $url = remove_query_arg( array('_wpnonce' , 'recaptcha-action' , 'settings-updated' ) );
190
- ?><a class="button" href="<?php echo $url ?>"><?php _e( 'Cancel' ) ?></a><?php
191
- }
192
-
193
- public function input_radio( $args ) {
194
- extract($args); // name, items
195
- $option = get_option( $name );
196
- foreach ( $items as $item ) {
197
- extract( $item ); // value, label
198
- ?><label for="<?php echo "$name-$value" ?>"><?php
199
- ?><input id="<?php echo "$name-$value" ?>" type="radio" name="<?php echo $name ?>" value="<?php echo $value ?>" <?php checked($value,$option,true) ?> />
200
- <?php
201
- echo $label;
202
- ?></label><br /><?php
203
- }
204
- }
205
-
206
- public function input_checkbox($args) {
207
- extract($args);
208
- $value = get_option( $name );
209
- ?><label for="<?php echo $name ?>"><?php
210
- ?><input id="<?php echo $name ?>" type="checkbox" name="<?php echo $name ?>" value="1" <?php checked($value,1,true) ?> />
211
- <?php
212
- echo $label;
213
- ?></label><?php
214
- }
215
- public function input_text( $args ) {
216
- extract( $args );
217
- $value = get_option( $name );
218
- ?><input type="text" class="regular-text ltr" name="<?php echo $name ?>" value="<?php //echo $value ?>" /><?php
219
- }
220
-
221
- public function select_theme() {
222
- $option_name = 'recaptcha_theme';
223
-
224
- $themes = array(
225
- 'light' => array(
226
- 'label' => __('Light','wp-recaptcha-integration') ,
227
- 'flavor' => 'grecaptcha',
228
- ),
229
- 'dark' => array(
230
- 'label' => __('Dark','wp-recaptcha-integration') ,
231
- 'flavor' => 'grecaptcha',
232
- ),
233
-
234
- 'red' => array(
235
- 'label' => __('Red','wp-recaptcha-integration') ,
236
- 'flavor' => 'recaptcha',
237
- ),
238
- 'white' => array(
239
- 'label' => __('White','wp-recaptcha-integration') ,
240
- 'flavor' => 'recaptcha',
241
- ),
242
- 'blackglass' => array(
243
- 'label' => __('Black Glass','wp-recaptcha-integration') ,
244
- 'flavor' => 'recaptcha',
245
- ),
246
- 'clean' => array(
247
- 'label' => __('Clean','wp-recaptcha-integration') ,
248
- 'flavor' => 'recaptcha',
249
- ),
250
- 'custom' => array(
251
- 'label' => __('Custom','wp-recaptcha-integration') ,
252
- 'flavor' => 'recaptcha',
253
- ),
254
- );
255
-
256
- $option_theme = get_option($option_name);
257
- $option_flavor = get_option( 'recaptcha_flavor' );
258
-
259
- ?><div class="recaptcha-select-theme flavor-<?php echo $option_flavor ?>"><?php
260
-
261
- foreach ( $themes as $value => $theme ) {
262
- extract( $theme ); // label, flavor
263
- ?><div class="theme-item flavor-<?php echo $flavor ?>"><?php
264
- ?><input <?php checked($value,$option_theme,true); ?> id="<?php echo "$option_name-$value" ?>" type="radio" name="<?php echo $option_name ?>" value="<?php echo $value ?>" /><?php
265
- ?><label for="<?php echo "$option_name-$value" ?>"><?php
266
- ?><span class="title"><?php
267
- echo $label;
268
- ?></span><?php
269
- if ( $value == 'custom' ) {
270
- ?><span class="visual"><?php
271
- _e( 'Unstyled HTML to apply your own Stylesheets.' , 'wp-recaptcha-integration' );
272
- ?></span><?php
273
- } else {
274
- $src = plugins_url( "images/{$flavor}-theme-{$value}.png" , dirname(__FILE__));
275
- printf( '<img src="%s" alt="%s" />' , $src , $label );
276
- }
277
- ?></label><?php
278
- ?></div><?php
279
-
280
- }
281
- ?></div><?php
282
- ?></div><?php
283
- }
284
- public function add_options_page() {
285
- $page_slug = add_options_page(
286
- __('ReCaptcha','wp-recaptcha-integration'), __('ReCaptcha','wp-recaptcha-integration'),
287
- 'manage_options', 'recaptcha',
288
- array(&$this,'render_options_page')
289
- );
290
- add_action( "load-$page_slug" , array( &$this , 'enqueue_styles' ) );
291
- }
292
- public function enqueue_styles() {
293
- wp_enqueue_style( 'recaptcha-options' , plugins_url( "css/recaptcha-options.css" , dirname(__FILE__)) );
294
- wp_enqueue_script( 'recaptcha-options' , plugins_url( "js/recaptcha-options.js" , dirname(__FILE__)) , array( 'jquery' ) );
295
- remove_action('admin_notices',array( &$this , 'api_key_notice'));
296
- }
297
- public function render_options_page() {
298
- ?><div class="wrap"><?php
299
- ?><h2><?php /*icon*/
300
- _e('Settings');
301
- echo ' › ';
302
- _e( 'ReCaptcha' , 'wp-recaptcha-integration' );
303
- ?></h2><?php
304
- /* ?><p><?php _e( '...' , 'googlefont' ); ?></p><?php */
305
- ?><form action="options.php" method="post"><?php
306
- settings_fields( 'recaptcha_options' );
307
- do_settings_sections( 'recaptcha' );
308
- ?><input name="submit" class="button button-primary" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" /><?php
309
- ?></form><?php
310
- ?></div><?php
311
- }
312
- public function sanitize_flavor( $flavor ) {
313
- if ( in_array($flavor,array('recaptcha','grecaptcha')) )
314
- return $flavor;
315
- return 'grecaptcha';
316
- }
317
- public function sanitize_theme( $theme ) {
318
- $themes_available = array(
319
- 'recaptcha' => array( 'white','red','blackglass','clean','custom' ),
320
- 'grecaptcha' => array( 'light','dark' ),
321
- );
322
- $flavor = get_option('recaptcha_flavor');
323
-
324
- if ( isset($themes_available[$flavor] ) && in_array($theme,$themes_available[$flavor]) )
325
- return $theme;
326
- else if ( isset($themes_available[$flavor] ) )
327
- return $themes_available[$flavor][0];
328
- return 'light';
329
- }
330
-
331
- }
332
-
333
-
334
- WordPress_reCaptcha_Options::instance();
335
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/recaptcha-options.js CHANGED
@@ -11,12 +11,29 @@
11
 
12
 
13
  $(document).on('click','#test-api-key' , function(e){
14
- console.log( $(this).prop('href') );
15
  if ( ! $('#recaptcha-test-result').length )
16
  $(this).closest('div').append('<div id="recaptcha-test-result" />');
17
- $('#recaptcha-test-result').load( $(this).prop('href') ,{},function(e){console.log(e);});
18
  e.preventDefault();
19
  e.stopPropagation();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  });
21
-
22
  })(jQuery);
11
 
12
 
13
  $(document).on('click','#test-api-key' , function(e){
 
14
  if ( ! $('#recaptcha-test-result').length )
15
  $(this).closest('div').append('<div id="recaptcha-test-result" />');
16
+ $('#recaptcha-test-result').load( $(this).prop('href') );
17
  e.preventDefault();
18
  e.stopPropagation();
19
+ $(this).remove();
20
+ return false;
21
+ });
22
+ $(document).on('click','#recaptcha-test-verification' , function(e){
23
+ var data = {
24
+ 'action' : 'recaptcha-test-verification',
25
+ '_wpnonce' : $('[name="recaptcha-test-verification-nonce"]').val(),
26
+ 'g-recaptcha-response' : $('#g-recaptcha-response').val()
27
+ };
28
+
29
+ $.post( ajaxurl ,
30
+ data ,
31
+ function(response) {
32
+ $('#recaptcha-test-result').html(response);
33
+ });
34
+
35
+ e.preventDefault();
36
+ e.stopPropagation();
37
+ return false;
38
  });
 
39
  })(jQuery);
languages/wp-recaptcha-integration-de_DE.mo CHANGED
Binary file
languages/wp-recaptcha-integration-de_DE.po CHANGED
@@ -1,9 +1,9 @@
1
  msgid ""
2
  msgstr ""
3
- "Project-Id-Version: WordPress reCaptcha Integration v0.9.0\n"
4
  "Report-Msgid-Bugs-To: \n"
5
  "POT-Creation-Date: \n"
6
- "PO-Revision-Date: 2014-12-19 18:17:10+0000\n"
7
  "Last-Translator: admin <joern@flyingletters.com>\n"
8
  "Language-Team: \n"
9
  "MIME-Version: 1.0\n"
@@ -21,43 +21,43 @@ msgstr ""
21
  "X-Textdomain-Support: yes"
22
 
23
  #: inc/ninja_forms_field_recaptcha.php:67
24
- #: wp-recaptcha-integration.php:118
25
- #: wp-recaptcha-integration.php:125
26
  #@ wp-recaptcha-integration
27
  msgid "<strong>Error:</strong> the Captcha didn’t verify."
28
  msgstr "<strong>Fehler:</strong> Sicherheitstest nicht bestanden"
29
 
30
- #: wp-recaptcha-integration.php:160
31
  #@ wp-recaptcha-integration
32
  msgid "Sorry, the Captcha didn’t verify."
33
  msgstr "Tut uns leid, aber Sie haben den Sicherheitstest nicht bestanden."
34
 
35
- #: wp-recaptcha-integration.php:200
36
  #@ wp-recaptcha-integration
37
  msgid "Incorrect please try again"
38
  msgstr "Falsch. Bitte noch einmal versuchen"
39
 
40
- #: wp-recaptcha-integration.php:202
41
  #@ wp-recaptcha-integration
42
  msgid "Enter the words above:"
43
  msgstr "Geben Sie die Wörten oben ein."
44
 
45
- #: wp-recaptcha-integration.php:203
46
  #@ wp-recaptcha-integration
47
  msgid "Enter the numbers you hear:"
48
  msgstr "Geben Sie die Zahlen ein, die Sie hören:"
49
 
50
- #: wp-recaptcha-integration.php:207
51
  #@ wp-recaptcha-integration
52
  msgid "Get another CAPTCHA"
53
  msgstr "Anderes CAPTCHA."
54
 
55
- #: wp-recaptcha-integration.php:208
56
  #@ wp-recaptcha-integration
57
  msgid "Get an audio CAPTCHA"
58
  msgstr "Audio CAPTCHA"
59
 
60
- #: wp-recaptcha-integration.php:209
61
  #@ wp-recaptcha-integration
62
  msgid "Get an image CAPTCHA"
63
  msgstr "Bild CAPTCHA"
@@ -88,7 +88,7 @@ msgstr ""
88
  msgid "The Captcha didn’t verify."
89
  msgstr "Sicherheitstest nicht bestanden"
90
 
91
- #: inc/recaptcha-options.php:36
92
  #, php-format
93
  #@ wp-recaptcha-integration
94
  msgid "<strong>reCaptcha needs your attention:</strong> To make it work You need to enter an api key. <br />You can do so at the <a href=\"%s\">reCaptcha settings page</a>."
@@ -97,88 +97,88 @@ msgstr ""
97
  "braucht Deine Aufmerksamkeit:</strong> Damit das reCaptch funktioniert, mußt Du einen API-Schlüssel eintragen. <br />Zu den <a \n"
98
  "href=\"%s\">reCaptcha Einstellungen</a>."
99
 
100
- #: inc/recaptcha-options.php:52
101
  #@ wp-recaptcha-integration
102
  msgid "Public Key"
103
  msgstr "Public Key"
104
 
105
- #: inc/recaptcha-options.php:53
106
  #@ wp-recaptcha-integration
107
  msgid "Private Key"
108
  msgstr "Private Key"
109
 
110
- #: inc/recaptcha-options.php:54
111
- #: inc/recaptcha-options.php:61
112
  #@ wp-recaptcha-integration
113
  msgid "Connecting"
114
  msgstr "Verbindung"
115
 
116
- #: inc/recaptcha-options.php:73
117
  #@ wp-recaptcha-integration
118
  msgid "Features"
119
  msgstr "Funktionen"
120
 
121
- #: inc/recaptcha-options.php:75
122
  #@ wp-recaptcha-integration
123
  msgid "Flavor"
124
  msgstr "Geschmacksrichtung"
125
 
126
- #: inc/recaptcha-options.php:86
127
  #@ wp-recaptcha-integration
128
  msgid "Old style reCAPTCHA where you type some cryptic text"
129
  msgstr "Klassisch, man muß kryptische Wörter eingeben"
130
 
131
- #: inc/recaptcha-options.php:91
132
  #@ wp-recaptcha-integration
133
  msgid "Theme"
134
  msgstr "Theme"
135
 
136
- #: inc/recaptcha-options.php:94
137
  #@ wp-recaptcha-integration
138
  msgid "Protect Comments"
139
  msgstr "Kommentare schützen"
140
 
141
- #: inc/recaptcha-options.php:96
142
  #@ wp-recaptcha-integration
143
  msgid "Protect comment forms with recaptcha."
144
  msgstr "Das Kommentarformular mit einem reCaptcha schützen"
145
 
146
- #: inc/recaptcha-options.php:99
147
  #@ wp-recaptcha-integration
148
  msgid "Protect Signup"
149
  msgstr "Registrierung schützen"
150
 
151
- #: inc/recaptcha-options.php:101
152
  #@ wp-recaptcha-integration
153
  msgid "Protect signup form with recaptcha."
154
  msgstr "Die Registrierung mit einem reCaptcha schützen."
155
 
156
- #: inc/recaptcha-options.php:104
157
  #@ wp-recaptcha-integration
158
  msgid "Protect Login"
159
  msgstr "Login schützen"
160
 
161
- #: inc/recaptcha-options.php:106
162
  #@ wp-recaptcha-integration
163
  msgid "Protect Login form with recaptcha."
164
  msgstr "Das Anmeldeformular mit einem reCaptcha schützen"
165
 
166
- #: inc/recaptcha-options.php:114
167
  #@ wp-recaptcha-integration
168
  msgid "Disable for known users"
169
  msgstr "Abschalten bei bekannten Benutzern"
170
 
171
- #: inc/recaptcha-options.php:116
172
  #@ wp-recaptcha-integration
173
  msgid "Disable reCaptcha verification for logged in users."
174
  msgstr "Die reCaptcha-Verifizierung für eingeloggte Benutzer deaktivieren"
175
 
176
- #: inc/recaptcha-options.php:120
177
  #@ wp-recaptcha-integration
178
  msgid "Please configure the public and private key. <a href=\"http://www.google.com/recaptcha/whyrecaptcha\">What are you trying to tell me?</a>"
179
  msgstr "Bitte konfigurieren Sie den privaten und den Öffentlichen Schlüssel (private &amp; public key). <a href=\"http://www.google.com/recaptcha/whyrecaptcha\">Was willst Du mir damit zu sagen?</a>"
180
 
181
- #: inc/recaptcha-options.php:130
182
  #, php-format
183
  #@ wp-recaptcha-integration
184
  msgid "Please register your blog through the <a href=\"%s\">Google reCAPTCHA admin page</a> and enter the public and private key in the fields below. <a href=\"%s\">What is this all about</a>"
@@ -187,89 +187,130 @@ msgstr ""
187
  "und trage unten den öffentlichen und privaten Schüssel ein. <a \n"
188
  "href=\"%s\">Was erzählst Du mir da?</a>"
189
 
190
- #: inc/recaptcha-options.php:136
191
  #@ wp-recaptcha-integration
192
  msgid "You already entered an API Key. Use the button below to enter it again."
193
  msgstr "Du hast schon einen API-Schlüssel eingetragen. Klick den Button unten, um es nochmal zu tun."
194
 
195
- #: inc/recaptcha-options.php:142
196
  #@ wp-recaptcha-integration
197
  msgid "New API Key"
198
  msgstr "Neuer API-Schlüssel"
199
 
200
- #: inc/recaptcha-options.php:149
201
  #@ default
202
  msgid "Cancel"
203
  msgstr ""
204
 
205
- #: inc/recaptcha-options.php:185
206
  #@ wp-recaptcha-integration
207
  msgid "Light"
208
  msgstr "Hell"
209
 
210
- #: inc/recaptcha-options.php:189
211
  #@ wp-recaptcha-integration
212
  msgid "Dark"
213
  msgstr "Dunkel"
214
 
215
- #: inc/recaptcha-options.php:194
216
  #@ wp-recaptcha-integration
217
  msgid "Red"
218
  msgstr "Rot"
219
 
220
- #: inc/recaptcha-options.php:198
221
  #@ wp-recaptcha-integration
222
  msgid "White"
223
  msgstr "Weiß"
224
 
225
- #: inc/recaptcha-options.php:202
226
  #@ wp-recaptcha-integration
227
  msgid "Black Glass"
228
  msgstr "Schwarzes Glas"
229
 
230
- #: inc/recaptcha-options.php:206
231
  #@ wp-recaptcha-integration
232
  msgid "Clean"
233
  msgstr "Clean"
234
 
235
- #: inc/recaptcha-options.php:210
236
  #@ wp-recaptcha-integration
237
  msgid "Custom"
238
  msgstr "Eigenes"
239
 
240
- #: inc/recaptcha-options.php:230
241
  #@ wp-recaptcha-integration
242
  msgid "Unstyled HTML to apply your own Stylesheets."
243
  msgstr "Pures HTML für Deine eigenen Stylessheets"
244
 
245
- #: inc/recaptcha-options.php:245
246
- #: inc/recaptcha-options.php:261
247
  #@ wp-recaptcha-integration
248
  msgid "ReCaptcha"
249
  msgstr "ReCaptcha"
250
 
251
- #: inc/recaptcha-options.php:259
252
  #@ default
253
  msgid "Settings"
254
  msgstr ""
255
 
256
- #: inc/recaptcha-options.php:267
257
- #@ default
258
- msgid "Save Changes"
259
- msgstr ""
260
-
261
- #: inc/recaptcha-options.php:82
262
  #@ wp-recaptcha-integration
263
  msgid "No Captcha where you just click a button"
264
  msgstr "No Captcha. Einfach Checkbox anklicken."
265
 
266
- #: inc/recaptcha-options.php:109
267
  #@ wp-recaptcha-integration
268
  msgid "Protect Lost Password"
269
  msgstr "Passwort verloren schützen"
270
 
271
- #: inc/recaptcha-options.php:111
272
  #@ wp-recaptcha-integration
273
  msgid "Protect Lost Password form with recaptcha."
274
  msgstr "Das Passwort Verloren Formular mit einem reCaptcha schützen"
275
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  msgid ""
2
  msgstr ""
3
+ "Project-Id-Version: WP reCaptcha Integration v0.9.2\n"
4
  "Report-Msgid-Bugs-To: \n"
5
  "POT-Creation-Date: \n"
6
+ "PO-Revision-Date: 2014-12-21 17:02:22+0000\n"
7
  "Last-Translator: admin <joern@flyingletters.com>\n"
8
  "Language-Team: \n"
9
  "MIME-Version: 1.0\n"
21
  "X-Textdomain-Support: yes"
22
 
23
  #: inc/ninja_forms_field_recaptcha.php:67
24
+ #: wp-recaptcha-integration.php:129
25
+ #: wp-recaptcha-integration.php:136
26
  #@ wp-recaptcha-integration
27
  msgid "<strong>Error:</strong> the Captcha didn’t verify."
28
  msgstr "<strong>Fehler:</strong> Sicherheitstest nicht bestanden"
29
 
30
+ #: wp-recaptcha-integration.php:174
31
  #@ wp-recaptcha-integration
32
  msgid "Sorry, the Captcha didn’t verify."
33
  msgstr "Tut uns leid, aber Sie haben den Sicherheitstest nicht bestanden."
34
 
35
+ #: wp-recaptcha-integration.php:216
36
  #@ wp-recaptcha-integration
37
  msgid "Incorrect please try again"
38
  msgstr "Falsch. Bitte noch einmal versuchen"
39
 
40
+ #: wp-recaptcha-integration.php:218
41
  #@ wp-recaptcha-integration
42
  msgid "Enter the words above:"
43
  msgstr "Geben Sie die Wörten oben ein."
44
 
45
+ #: wp-recaptcha-integration.php:219
46
  #@ wp-recaptcha-integration
47
  msgid "Enter the numbers you hear:"
48
  msgstr "Geben Sie die Zahlen ein, die Sie hören:"
49
 
50
+ #: wp-recaptcha-integration.php:223
51
  #@ wp-recaptcha-integration
52
  msgid "Get another CAPTCHA"
53
  msgstr "Anderes CAPTCHA."
54
 
55
+ #: wp-recaptcha-integration.php:224
56
  #@ wp-recaptcha-integration
57
  msgid "Get an audio CAPTCHA"
58
  msgstr "Audio CAPTCHA"
59
 
60
+ #: wp-recaptcha-integration.php:225
61
  #@ wp-recaptcha-integration
62
  msgid "Get an image CAPTCHA"
63
  msgstr "Bild CAPTCHA"
88
  msgid "The Captcha didn’t verify."
89
  msgstr "Sicherheitstest nicht bestanden"
90
 
91
+ #: inc/class-wp-recaptcha-options.php:148
92
  #, php-format
93
  #@ wp-recaptcha-integration
94
  msgid "<strong>reCaptcha needs your attention:</strong> To make it work You need to enter an api key. <br />You can do so at the <a href=\"%s\">reCaptcha settings page</a>."
97
  "braucht Deine Aufmerksamkeit:</strong> Damit das reCaptch funktioniert, mußt Du einen API-Schlüssel eintragen. <br />Zu den <a \n"
98
  "href=\"%s\">reCaptcha Einstellungen</a>."
99
 
100
+ #: inc/class-wp-recaptcha-options.php:169
101
  #@ wp-recaptcha-integration
102
  msgid "Public Key"
103
  msgstr "Public Key"
104
 
105
+ #: inc/class-wp-recaptcha-options.php:170
106
  #@ wp-recaptcha-integration
107
  msgid "Private Key"
108
  msgstr "Private Key"
109
 
110
+ #: inc/class-wp-recaptcha-options.php:171
111
+ #: inc/class-wp-recaptcha-options.php:177
112
  #@ wp-recaptcha-integration
113
  msgid "Connecting"
114
  msgstr "Verbindung"
115
 
116
+ #: inc/class-wp-recaptcha-options.php:239
117
  #@ wp-recaptcha-integration
118
  msgid "Features"
119
  msgstr "Funktionen"
120
 
121
+ #: inc/class-wp-recaptcha-options.php:187
122
  #@ wp-recaptcha-integration
123
  msgid "Flavor"
124
  msgstr "Geschmacksrichtung"
125
 
126
+ #: inc/class-wp-recaptcha-options.php:198
127
  #@ wp-recaptcha-integration
128
  msgid "Old style reCAPTCHA where you type some cryptic text"
129
  msgstr "Klassisch, man muß kryptische Wörter eingeben"
130
 
131
+ #: inc/class-wp-recaptcha-options.php:203
132
  #@ wp-recaptcha-integration
133
  msgid "Theme"
134
  msgstr "Theme"
135
 
136
+ #: inc/class-wp-recaptcha-options.php:214
137
  #@ wp-recaptcha-integration
138
  msgid "Protect Comments"
139
  msgstr "Kommentare schützen"
140
 
141
+ #: inc/class-wp-recaptcha-options.php:216
142
  #@ wp-recaptcha-integration
143
  msgid "Protect comment forms with recaptcha."
144
  msgstr "Das Kommentarformular mit einem reCaptcha schützen"
145
 
146
+ #: inc/class-wp-recaptcha-options.php:219
147
  #@ wp-recaptcha-integration
148
  msgid "Protect Signup"
149
  msgstr "Registrierung schützen"
150
 
151
+ #: inc/class-wp-recaptcha-options.php:221
152
  #@ wp-recaptcha-integration
153
  msgid "Protect signup form with recaptcha."
154
  msgstr "Die Registrierung mit einem reCaptcha schützen."
155
 
156
+ #: inc/class-wp-recaptcha-options.php:224
157
  #@ wp-recaptcha-integration
158
  msgid "Protect Login"
159
  msgstr "Login schützen"
160
 
161
+ #: inc/class-wp-recaptcha-options.php:226
162
  #@ wp-recaptcha-integration
163
  msgid "Protect Login form with recaptcha."
164
  msgstr "Das Anmeldeformular mit einem reCaptcha schützen"
165
 
166
+ #: inc/class-wp-recaptcha-options.php:234
167
  #@ wp-recaptcha-integration
168
  msgid "Disable for known users"
169
  msgstr "Abschalten bei bekannten Benutzern"
170
 
171
+ #: inc/class-wp-recaptcha-options.php:236
172
  #@ wp-recaptcha-integration
173
  msgid "Disable reCaptcha verification for logged in users."
174
  msgstr "Die reCaptcha-Verifizierung für eingeloggte Benutzer deaktivieren"
175
 
176
+ #: inc/class-wp-recaptcha-options.php:242
177
  #@ wp-recaptcha-integration
178
  msgid "Please configure the public and private key. <a href=\"http://www.google.com/recaptcha/whyrecaptcha\">What are you trying to tell me?</a>"
179
  msgstr "Bitte konfigurieren Sie den privaten und den Öffentlichen Schlüssel (private &amp; public key). <a href=\"http://www.google.com/recaptcha/whyrecaptcha\">Was willst Du mir damit zu sagen?</a>"
180
 
181
+ #: inc/class-wp-recaptcha-options.php:255
182
  #, php-format
183
  #@ wp-recaptcha-integration
184
  msgid "Please register your blog through the <a href=\"%s\">Google reCAPTCHA admin page</a> and enter the public and private key in the fields below. <a href=\"%s\">What is this all about</a>"
187
  "und trage unten den öffentlichen und privaten Schüssel ein. <a \n"
188
  "href=\"%s\">Was erzählst Du mir da?</a>"
189
 
190
+ #: inc/class-wp-recaptcha-options.php:263
191
  #@ wp-recaptcha-integration
192
  msgid "You already entered an API Key. Use the button below to enter it again."
193
  msgstr "Du hast schon einen API-Schlüssel eingetragen. Klick den Button unten, um es nochmal zu tun."
194
 
195
+ #: inc/class-wp-recaptcha-options.php:274
196
  #@ wp-recaptcha-integration
197
  msgid "New API Key"
198
  msgstr "Neuer API-Schlüssel"
199
 
200
+ #: inc/class-wp-recaptcha-options.php:331
201
  #@ default
202
  msgid "Cancel"
203
  msgstr ""
204
 
205
+ #: inc/class-wp-recaptcha-options.php:401
206
  #@ wp-recaptcha-integration
207
  msgid "Light"
208
  msgstr "Hell"
209
 
210
+ #: inc/class-wp-recaptcha-options.php:405
211
  #@ wp-recaptcha-integration
212
  msgid "Dark"
213
  msgstr "Dunkel"
214
 
215
+ #: inc/class-wp-recaptcha-options.php:410
216
  #@ wp-recaptcha-integration
217
  msgid "Red"
218
  msgstr "Rot"
219
 
220
+ #: inc/class-wp-recaptcha-options.php:414
221
  #@ wp-recaptcha-integration
222
  msgid "White"
223
  msgstr "Weiß"
224
 
225
+ #: inc/class-wp-recaptcha-options.php:418
226
  #@ wp-recaptcha-integration
227
  msgid "Black Glass"
228
  msgstr "Schwarzes Glas"
229
 
230
+ #: inc/class-wp-recaptcha-options.php:422
231
  #@ wp-recaptcha-integration
232
  msgid "Clean"
233
  msgstr "Clean"
234
 
235
+ #: inc/class-wp-recaptcha-options.php:426
236
  #@ wp-recaptcha-integration
237
  msgid "Custom"
238
  msgstr "Eigenes"
239
 
240
+ #: inc/class-wp-recaptcha-options.php:446
241
  #@ wp-recaptcha-integration
242
  msgid "Unstyled HTML to apply your own Stylesheets."
243
  msgstr "Pures HTML für Deine eigenen Stylessheets"
244
 
245
+ #: inc/class-wp-recaptcha-options.php:490
246
+ #: inc/class-wp-recaptcha-options.php:514
247
  #@ wp-recaptcha-integration
248
  msgid "ReCaptcha"
249
  msgstr "ReCaptcha"
250
 
251
+ #: inc/class-wp-recaptcha-options.php:512
252
  #@ default
253
  msgid "Settings"
254
  msgstr ""
255
 
256
+ #: inc/class-wp-recaptcha-options.php:194
 
 
 
 
 
257
  #@ wp-recaptcha-integration
258
  msgid "No Captcha where you just click a button"
259
  msgstr "No Captcha. Einfach Checkbox anklicken."
260
 
261
+ #: inc/class-wp-recaptcha-options.php:229
262
  #@ wp-recaptcha-integration
263
  msgid "Protect Lost Password"
264
  msgstr "Passwort verloren schützen"
265
 
266
+ #: inc/class-wp-recaptcha-options.php:231
267
  #@ wp-recaptcha-integration
268
  msgid "Protect Lost Password form with recaptcha."
269
  msgstr "Das Passwort Verloren Formular mit einem reCaptcha schützen"
270
 
271
+ #: inc/class-wp-recaptcha-options.php:89
272
+ #: inc/class-wp-recaptcha-options.php:101
273
+ #@ wp-recaptcha-integration
274
+ msgid "reCaptcha Settings"
275
+ msgstr "reCaptcha Einstellungen"
276
+
277
+ #: inc/class-wp-recaptcha-options.php:90
278
+ #@ wp-recaptcha-integration
279
+ msgid "reCaptcha"
280
+ msgstr "reCaptcha"
281
+
282
+ #: inc/class-wp-recaptcha-options.php:275
283
+ #@ wp-recaptcha-integration
284
+ msgid "Test API Key"
285
+ msgstr "API Schlüssel testen"
286
+
287
+ #: inc/class-wp-recaptcha-options.php:294
288
+ #@ wp-recaptcha-integration
289
+ msgid "Test verfication"
290
+ msgstr "Captcha-Prüfung testen"
291
+
292
+ #: inc/class-wp-recaptcha-options.php:307
293
+ #@ wp-recaptcha-integration
294
+ msgid "The secret Key is missing."
295
+ msgstr "Der geheime Schlüssel fehlt."
296
+
297
+ #: inc/class-wp-recaptcha-options.php:308
298
+ #@ wp-recaptcha-integration
299
+ msgid "The secret Key is invalid. You better check your domain configuration and enter it again."
300
+ msgstr "Der geheime Schlüssel ist ungültig. Am besten prüfst Du Deine Domain.-Konfiguration und trägst ihn nochmal ein."
301
+
302
+ #: inc/class-wp-recaptcha-options.php:309
303
+ #@ wp-recaptcha-integration
304
+ msgid "The user response was missing "
305
+ msgstr ""
306
+
307
+ #: inc/class-wp-recaptcha-options.php:310
308
+ #@ wp-recaptcha-integration
309
+ msgid "Invalid user response"
310
+ msgstr ""
311
+
312
+ #: inc/class-wp-recaptcha-options.php:319
313
+ #@ wp-recaptcha-integration
314
+ msgid "Works! All good!"
315
+ msgstr "Läuft! Sehr gut."
316
+
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: security, captcha, recaptcha, no captcha, login, signup, contact form 7, ninja forms
5
  Requires at least: 3.8
6
  Tested up to: 4.1
7
- Stable tag: trunk
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -19,16 +19,15 @@ form 7 as well as a plugin API for your own integrations.
19
  = Features: =
20
  - Secures login, signup and comments with a recaptcha.
21
  - Supports old as well as new reCaptcha.
 
22
  - [Ninja Forms](http://ninjaforms.com/) integration
23
  - [Contact Form 7](https://wordpress.org/plugins/contact-form-7/) integration
24
 
25
  Latest Files on GitHub: [https://github.com/mcguffin/wp-recaptcha-integration](https://github.com/mcguffin/wp-recaptcha-integration)
26
 
27
  = Known Limitations =
28
- - Currently you can't have more than one reCaptcha on a page.
29
- This may affect you for example when you have a contact page with a comment form.
30
- For old style reCaptcha this cannot be fixed. For the new Style reCaptchas
31
- this is due to be implemented in the near future.
32
 
33
  - On a Contact Form 7 when the reCaptcha is disabled (e.g. for logged in users) the field
34
  label will be still visible. This is due to CF7 Shortcode architecture, and can't be fixed.
@@ -92,6 +91,11 @@ I will migrate all the translation stuff there.
92
 
93
  == Changelog ==
94
 
 
 
 
 
 
95
  = 0.9.1 =
96
  - Add testing tool for checking the api key.
97
  - Fixes
4
  Tags: security, captcha, recaptcha, no captcha, login, signup, contact form 7, ninja forms
5
  Requires at least: 3.8
6
  Tested up to: 4.1
7
+ Stable tag: 1.0.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
19
  = Features: =
20
  - Secures login, signup and comments with a recaptcha.
21
  - Supports old as well as new reCaptcha.
22
+ - Multisite Support
23
  - [Ninja Forms](http://ninjaforms.com/) integration
24
  - [Contact Form 7](https://wordpress.org/plugins/contact-form-7/) integration
25
 
26
  Latest Files on GitHub: [https://github.com/mcguffin/wp-recaptcha-integration](https://github.com/mcguffin/wp-recaptcha-integration)
27
 
28
  = Known Limitations =
29
+ - You can't have more than one old style reCaptcha on a page. This is a limitiation of
30
+ reCaptcha itself. If that's an issue for you, you should use the no Captcha Form.
 
 
31
 
32
  - On a Contact Form 7 when the reCaptcha is disabled (e.g. for logged in users) the field
33
  label will be still visible. This is due to CF7 Shortcode architecture, and can't be fixed.
91
 
92
  == Changelog ==
93
 
94
+ = 1.0.0 =
95
+ - Allow more than one no Captcha per page
96
+ - Test captcha verification in Settings
97
+ - Multisite support.
98
+
99
  = 0.9.1 =
100
  - Add testing tool for checking the api key.
101
  - Fixes
wp-recaptcha-integration.php CHANGED
@@ -3,19 +3,37 @@
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 stle reCaptcha. Provides of the box integration for signup, login, comment forms, lost password, Ninja Forms and contact form 7.
6
- Version: 0.9.1
7
  Author: Jörn Lund
8
  Author URI: https://github.com/mcguffin/
9
  */
10
 
 
11
 
 
 
 
12
 
 
 
 
 
13
 
14
- class WordPress_reCaptcha {
 
 
 
 
 
 
 
 
 
15
 
16
  private $_has_api_key = false;
17
 
18
  private $last_error = '';
 
19
 
20
  /**
21
  * Holding the singleton instance
@@ -23,7 +41,7 @@ class WordPress_reCaptcha {
23
  private static $_instance = null;
24
 
25
  /**
26
- * @return WordPress_reCaptcha_Options The options manager instance
27
  */
28
  public static function instance(){
29
  if ( is_null( self::$_instance ) )
@@ -32,36 +50,49 @@ class WordPress_reCaptcha {
32
  }
33
 
34
  /**
35
- * Prevent from creating more than one instance
36
  */
37
- private function __clone() {
38
- }
39
 
40
  /**
41
  * Prevent from creating more than one instance
42
  */
43
  private function __construct() {
44
- add_option('recaptcha_publickey','');
45
- add_option('recaptcha_privatekey','');
46
-
47
- add_option('recaptcha_flavor','grecaptcha');
48
- add_option('recaptcha_theme','light');
49
- add_option('recaptcha_enable_comments' , true);
50
- add_option('recaptcha_enable_signup' , true);
51
- add_option('recaptcha_enable_login' , false);
52
- add_option('recaptcha_enable_lostpw' , false);
53
- add_option('recaptcha_disable_for_known_users' , true);
54
-
55
- $this->_has_api_key = get_option( 'recaptcha_publickey' ) && get_option( 'recaptcha_privatekey' );
 
 
 
 
 
 
 
 
 
 
 
56
 
57
  if ( $this->_has_api_key ) {
58
- add_action( 'wp_head' , array($this,'recaptcha_script') );
 
59
 
60
  add_action('init' , array(&$this,'init') );
61
  add_action('plugins_loaded' , array(&$this,'plugins_loaded') );
62
 
63
- if ( get_option('recaptcha_enable_signup') || get_option('recaptcha_enable_login') || get_option('recaptcha_enable_lostpw') )
64
- add_action( 'login_head' , array(&$this,'recaptcha_script') );
 
 
65
  }
66
 
67
  register_activation_hook( __FILE__ , array( __CLASS__ , 'activate' ) );
@@ -89,27 +120,27 @@ class WordPress_reCaptcha {
89
 
90
  $require_recaptcha = $this->is_required();
91
 
92
- if ( get_option('recaptcha_enable_comments') && $require_recaptcha ) {
93
- add_action('comment_form',array($this,'print_recaptcha_html'));
94
  add_action('pre_comment_on_post',array($this,'recaptcha_check_or_die'));
95
  // add action @ comment approve
96
  }
97
- if ( get_option('recaptcha_enable_signup') && $require_recaptcha ) {
98
- add_action('register_form',array($this,'print_recaptcha_html'));
99
  add_filter('registration_errors',array(&$this,'login_errors'));
100
  }
101
- if ( get_option('recaptcha_enable_login') && $require_recaptcha ) {
102
- add_action('login_form',array($this,'print_recaptcha_html'));
103
  add_filter('wp_authenticate_user',array(&$this,'deny_login'),99 );
104
  }
105
- if ( get_option('recaptcha_enable_lostpw') && $require_recaptcha ) {
106
- add_action('lostpassword_form' , array($this,'print_recaptcha_html'));
107
  add_filter('lostpassword_post' , array(&$this,'recaptcha_check_or_die'),99 );
108
  }
109
  }
110
 
111
  function is_required() {
112
- $is_required = ! ( get_option('recaptcha_disable_for_known_users') && current_user_can( 'read' ) );
113
  return apply_filters( 'recaptcha_required' , $is_required );
114
  }
115
 
@@ -127,12 +158,11 @@ class WordPress_reCaptcha {
127
  return $errors;
128
  }
129
 
130
- function recaptcha_script( $flavor = '' ) {
131
  if ( empty( $flavor ) )
132
- $flavor = get_option( 'recaptcha_flavor' );
133
  switch ( $flavor ) {
134
  case 'grecaptcha':
135
- ?><script src="https://www.google.com/recaptcha/api.js" async defer></script><?php
136
  ?><style type="text/css">
137
  #login {
138
  width:350px !important;
@@ -140,7 +170,7 @@ class WordPress_reCaptcha {
140
  </style><?php
141
  break;
142
  case 'recaptcha':
143
- $recaptcha_theme = get_option('recaptcha_theme');
144
  if ( $recaptcha_theme == 'custom' ) {
145
  ?><script type="text/javascript">
146
  var RecaptchaOptions = {
@@ -155,20 +185,40 @@ class WordPress_reCaptcha {
155
  };
156
  </script><?php
157
  }
 
158
  }
159
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  function recaptcha_check_or_die( ) {
161
  if ( ! $this->recaptcha_check() )
162
  wp_die( __("Sorry, the Captcha didn’t verify.",'wp-recaptcha-integration') );
163
  }
164
 
165
- function print_recaptcha_html( $flavor = '' ){
166
  echo $this->recaptcha_html( $flavor );
167
  }
168
 
169
  function recaptcha_html( $flavor = '' ) {
 
170
  if ( empty( $flavor ) )
171
- $flavor = get_option( 'recaptcha_flavor' );
172
  switch ( $flavor ) {
173
  case 'grecaptcha':
174
  return $this->grecaptcha_html();
@@ -179,8 +229,8 @@ class WordPress_reCaptcha {
179
 
180
  function old_recaptcha_html() {
181
  require_once dirname(__FILE__).'/recaptchalib.php';
182
- $public_key = get_option( 'recaptcha_publickey' );
183
- $recaptcha_theme = get_option('recaptcha_theme');
184
 
185
  if ($recaptcha_theme == 'custom')
186
  $return = $this->get_custom_html( $public_key );
@@ -190,8 +240,8 @@ class WordPress_reCaptcha {
190
  }
191
 
192
  function grecaptcha_html() {
193
- $public_key = get_option( 'recaptcha_publickey' );
194
- $theme = get_option('recaptcha_theme');
195
  $return = sprintf( '<div class="g-recaptcha" data-sitekey="%s" data-theme="%s"></div>',$public_key,$theme);
196
  return $return;
197
  }
@@ -226,8 +276,14 @@ class WordPress_reCaptcha {
226
  return $return;
227
  }
228
 
229
- function recaptcha_check() {
230
- switch ( get_option( 'recaptcha_flavor' ) ) {
 
 
 
 
 
 
231
  case 'grecaptcha':
232
  return $this->grecaptcha_check();
233
  case 'recaptcha':
@@ -235,7 +291,7 @@ class WordPress_reCaptcha {
235
  }
236
  }
237
  function grecaptcha_check() {
238
- $private_key = get_option( 'recaptcha_privatekey' );
239
  $user_response = isset( $_REQUEST['g-recaptcha-response'] ) ? $_REQUEST['g-recaptcha-response'] : false;
240
  if ( $user_response ) {
241
  $remote_ip = $_SERVER['REMOTE_ADDR'];
@@ -243,25 +299,48 @@ class WordPress_reCaptcha {
243
  $response = wp_remote_get( $url );
244
  if ( ! is_wp_error($response) ) {
245
  $response_data = wp_remote_retrieve_body( $response );
246
- $result = json_decode($response_data);
247
- return $result->success;
248
  }
249
  }
250
  return false;
251
  }
252
  function old_recaptcha_check() {
253
  require_once dirname(__FILE__).'/recaptchalib.php';
254
- $private_key = get_option( 'recaptcha_privatekey' );
255
- $response = recaptcha_check_answer( $private_key,
256
  $_SERVER["REMOTE_ADDR"],
257
  $_POST["recaptcha_challenge_field"],
258
  $_POST["recaptcha_response_field"]);
259
 
260
- if ( ! $response->is_valid )
261
- $this->last_error = $response->error;
262
 
263
- return $response->is_valid;
264
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
  /**
266
  * Fired on plugin activation
267
  */
@@ -274,22 +353,53 @@ class WordPress_reCaptcha {
274
  public static function deactivate() {
275
  }
276
  /**
277
- *
278
  */
279
  public static function uninstall() {
280
- delete_option( 'recaptcha_publickey' );
281
- delete_option( 'recaptcha_privatekey' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
282
 
283
- delete_option( 'recaptcha_flavor' );
284
- delete_option( 'recaptcha_theme' );
285
- delete_option( 'recaptcha_enable_comments' );
286
- delete_option( 'recaptcha_enable_signup' );
287
- delete_option( 'recaptcha_enable_login' );
288
- delete_option( 'recaptcha_disable_for_known_users' );
 
 
 
 
 
 
 
 
 
 
 
 
 
289
  }
290
  }
291
 
292
 
293
- WordPress_reCaptcha::instance();
294
 
295
- require_once dirname(__FILE__).'/inc/recaptcha-options.php';
 
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 stle reCaptcha. Provides of the box integration for signup, login, comment forms, lost password, Ninja Forms and contact form 7.
6
+ Version: 1.0.0
7
  Author: Jörn Lund
8
  Author URI: https://github.com/mcguffin/
9
  */
10
 
11
+ /* Copyright 2014 Jörn Lund (email : joern AT podpirate DOT org)
12
 
13
+ This program is free software; you can redistribute it and/or modify
14
+ it under the terms of the GNU General Public License, version 2, as
15
+ published by the Free Software Foundation.
16
 
17
+ This program is distributed in the hope that it will be useful,
18
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
+ GNU General Public License for more details.
21
 
22
+ You should have received a copy of the GNU General Public License
23
+ along with this program; if not, write to the Free Software
24
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
+ */
26
+
27
+
28
+
29
+ class WP_reCaptcha {
30
+
31
+ private static $_is_network_activated = null;
32
 
33
  private $_has_api_key = false;
34
 
35
  private $last_error = '';
36
+ private $_last_result;
37
 
38
  /**
39
  * Holding the singleton instance
41
  private static $_instance = null;
42
 
43
  /**
44
+ * @return WP_reCaptcha
45
  */
46
  public static function instance(){
47
  if ( is_null( self::$_instance ) )
50
  }
51
 
52
  /**
53
+ * Prevent from creating more instances
54
  */
55
+ private function __clone() { }
 
56
 
57
  /**
58
  * Prevent from creating more than one instance
59
  */
60
  private function __construct() {
61
+ add_option('recaptcha_flavor','grecaptcha'); // local
62
+ add_option('recaptcha_theme','light'); // local
63
+ add_option('recaptcha_publickey',''); // 1st global -> then local
64
+ add_option('recaptcha_privatekey',''); // 1st global -> then local
65
+
66
+ if ( WP_reCaptcha::is_network_activated() ) {
67
+ add_site_option('recaptcha_publickey',''); // 1st global -> then local
68
+ add_site_option('recaptcha_privatekey',''); // 1st global -> then local
69
+
70
+ add_site_option('recaptcha_enable_comments' , true); // global
71
+ add_site_option('recaptcha_enable_signup' , true); // global
72
+ add_site_option('recaptcha_enable_login' , false); // global
73
+ add_site_option('recaptcha_enable_lostpw' , false); // global
74
+ add_site_option('recaptcha_disable_for_known_users' , true); // global
75
+ $this->_has_api_key = get_site_option( 'recaptcha_publickey' ) && get_site_option( 'recaptcha_privatekey' );
76
+ } else {
77
+ add_option('recaptcha_enable_comments' , true); // global
78
+ add_option('recaptcha_enable_signup' , true); // global
79
+ add_option('recaptcha_enable_login' , false); // global
80
+ add_option('recaptcha_enable_lostpw' , false); // global
81
+ add_option('recaptcha_disable_for_known_users' , true); // global
82
+ $this->_has_api_key = get_option( 'recaptcha_publickey' ) && get_option( 'recaptcha_privatekey' );
83
+ }
84
 
85
  if ( $this->_has_api_key ) {
86
+ add_action( 'wp_head' , array($this,'recaptcha_head') );
87
+ add_action( 'wp_footer' , array($this,'recaptcha_foot') );
88
 
89
  add_action('init' , array(&$this,'init') );
90
  add_action('plugins_loaded' , array(&$this,'plugins_loaded') );
91
 
92
+ if ( $this->get_option('recaptcha_enable_signup') || $this->get_option('recaptcha_enable_login') || $this->get_option('recaptcha_enable_lostpw') ) {
93
+ add_action( 'login_head' , array(&$this,'recaptcha_head') );
94
+ add_action( 'login_footer' , array(&$this,'recaptcha_foot') );
95
+ }
96
  }
97
 
98
  register_activation_hook( __FILE__ , array( __CLASS__ , 'activate' ) );
120
 
121
  $require_recaptcha = $this->is_required();
122
 
123
+ if ( $this->get_option('recaptcha_enable_comments') && $require_recaptcha ) {
124
+ add_action('comment_form',array($this,'print_recaptcha_html'),10,0);
125
  add_action('pre_comment_on_post',array($this,'recaptcha_check_or_die'));
126
  // add action @ comment approve
127
  }
128
+ if ( $this->get_option('recaptcha_enable_signup') && $require_recaptcha ) {
129
+ add_action('register_form',array($this,'print_recaptcha_html'),10,0);
130
  add_filter('registration_errors',array(&$this,'login_errors'));
131
  }
132
+ if ( $this->get_option('recaptcha_enable_login') && $require_recaptcha ) {
133
+ add_action('login_form',array($this,'print_recaptcha_html'),10,0);
134
  add_filter('wp_authenticate_user',array(&$this,'deny_login'),99 );
135
  }
136
+ if ( $this->get_option('recaptcha_enable_lostpw') && $require_recaptcha ) {
137
+ add_action('lostpassword_form' , array($this,'print_recaptcha_html'),10,0);
138
  add_filter('lostpassword_post' , array(&$this,'recaptcha_check_or_die'),99 );
139
  }
140
  }
141
 
142
  function is_required() {
143
+ $is_required = ! ( $this->get_option('recaptcha_disable_for_known_users') && current_user_can( 'read' ) );
144
  return apply_filters( 'recaptcha_required' , $is_required );
145
  }
146
 
158
  return $errors;
159
  }
160
 
161
+ function recaptcha_head( $flavor = '' ) {
162
  if ( empty( $flavor ) )
163
+ $flavor = $this->get_option( 'recaptcha_flavor' );
164
  switch ( $flavor ) {
165
  case 'grecaptcha':
 
166
  ?><style type="text/css">
167
  #login {
168
  width:350px !important;
170
  </style><?php
171
  break;
172
  case 'recaptcha':
173
+ $recaptcha_theme = $this->get_option('recaptcha_theme');
174
  if ( $recaptcha_theme == 'custom' ) {
175
  ?><script type="text/javascript">
176
  var RecaptchaOptions = {
185
  };
186
  </script><?php
187
  }
188
+ break;
189
  }
190
  }
191
+ function recaptcha_foot( $flavor = '' ) {
192
+ if ( empty( $flavor ) )
193
+ $flavor = $this->get_option( 'recaptcha_flavor' );
194
+ switch ( $flavor ) {
195
+ case 'grecaptcha':
196
+ ?><script type="text/javascript">
197
+ function recaptchaLoadCallback(){
198
+ var e=document.getElementsByClassName('g-recaptcha');
199
+ for (var i=0;i<e.length;i++)
200
+ grecaptcha.render(e[i],{'sitekey':'<?php echo $this->get_option('recaptcha_publickey') ?>'});
201
+ }
202
+ </script><?php
203
+ ?><script src="https://www.google.com/recaptcha/api.js?onload=recaptchaLoadCallback&render=explicit" async defer></script><?php
204
+ break;
205
+ case 'recaptcha':
206
+ break;
207
+ }
208
+ }
209
  function recaptcha_check_or_die( ) {
210
  if ( ! $this->recaptcha_check() )
211
  wp_die( __("Sorry, the Captcha didn’t verify.",'wp-recaptcha-integration') );
212
  }
213
 
214
+ function print_recaptcha_html( $flavor = '' ) {
215
  echo $this->recaptcha_html( $flavor );
216
  }
217
 
218
  function recaptcha_html( $flavor = '' ) {
219
+
220
  if ( empty( $flavor ) )
221
+ $flavor = $this->get_option( 'recaptcha_flavor' );
222
  switch ( $flavor ) {
223
  case 'grecaptcha':
224
  return $this->grecaptcha_html();
229
 
230
  function old_recaptcha_html() {
231
  require_once dirname(__FILE__).'/recaptchalib.php';
232
+ $public_key = $this->get_option( 'recaptcha_publickey' );
233
+ $recaptcha_theme = $this->get_option('recaptcha_theme');
234
 
235
  if ($recaptcha_theme == 'custom')
236
  $return = $this->get_custom_html( $public_key );
240
  }
241
 
242
  function grecaptcha_html() {
243
+ $public_key = $this->get_option( 'recaptcha_publickey' );
244
+ $theme = $this->get_option('recaptcha_theme');
245
  $return = sprintf( '<div class="g-recaptcha" data-sitekey="%s" data-theme="%s"></div>',$public_key,$theme);
246
  return $return;
247
  }
276
  return $return;
277
  }
278
 
279
+ function get_last_result() {
280
+ return $this->_last_result;
281
+ }
282
+
283
+ function recaptcha_check( $flavor = '' ) {
284
+ if ( empty( $flavor ) )
285
+ $flavor = $this->get_option( 'recaptcha_flavor' );
286
+ switch ( $flavor ) {
287
  case 'grecaptcha':
288
  return $this->grecaptcha_check();
289
  case 'recaptcha':
291
  }
292
  }
293
  function grecaptcha_check() {
294
+ $private_key = $this->get_option( 'recaptcha_privatekey' );
295
  $user_response = isset( $_REQUEST['g-recaptcha-response'] ) ? $_REQUEST['g-recaptcha-response'] : false;
296
  if ( $user_response ) {
297
  $remote_ip = $_SERVER['REMOTE_ADDR'];
299
  $response = wp_remote_get( $url );
300
  if ( ! is_wp_error($response) ) {
301
  $response_data = wp_remote_retrieve_body( $response );
302
+ $this->_last_result = json_decode($response_data);
303
+ return $this->_last_result->success;
304
  }
305
  }
306
  return false;
307
  }
308
  function old_recaptcha_check() {
309
  require_once dirname(__FILE__).'/recaptchalib.php';
310
+ $private_key = $this->get_option( 'recaptcha_privatekey' );
311
+ $this->_last_result = recaptcha_check_answer( $private_key,
312
  $_SERVER["REMOTE_ADDR"],
313
  $_POST["recaptcha_challenge_field"],
314
  $_POST["recaptcha_response_field"]);
315
 
316
+ if ( ! $this->_last_result->is_valid )
317
+ $this->last_error = $this->_last_result->error;
318
 
319
+ return $this->_last_result->is_valid;
320
  }
321
+
322
+ public function get_option( $option_name ) {
323
+ switch ( $option_name ) {
324
+ case 'recaptcha_flavor':
325
+ case 'recaptcha_theme':
326
+ return get_option($option_name);
327
+ case 'recaptcha_publickey':
328
+ case 'recaptcha_privatekey':
329
+ $option_value = get_option($option_name);
330
+ if ( ! $option_value && WP_reCaptcha::is_network_activated() )
331
+ $option_value = get_site_option( $option_name );
332
+ return $option_value;
333
+ case 'recaptcha_enable_comments':
334
+ case 'recaptcha_enable_signup':
335
+ case 'recaptcha_enable_login':
336
+ case 'recaptcha_enable_lostpw':
337
+ case 'recaptcha_disable_for_known_users':
338
+ if ( WP_reCaptcha::is_network_activated() )
339
+ return get_site_option($option_name);
340
+ return get_option( $option_name );
341
+ }
342
+ }
343
+
344
  /**
345
  * Fired on plugin activation
346
  */
353
  public static function deactivate() {
354
  }
355
  /**
356
+ * Uninstall
357
  */
358
  public static function uninstall() {
359
+ if ( is_multisite() ) {
360
+ delete_site_option( 'recaptcha_publickey' );
361
+ delete_site_option( 'recaptcha_privatekey' );
362
+ delete_site_option( 'recaptcha_enable_comments' );
363
+ delete_site_option( 'recaptcha_enable_signup' );
364
+ delete_site_option( 'recaptcha_enable_login' );
365
+ delete_site_option( 'recaptcha_disable_for_known_users' );
366
+
367
+ foreach ( wp_get_sites() as $site) {
368
+ switch_to_blog( $site["blog_id"] );
369
+ delete_option( 'recaptcha_publickey' );
370
+ delete_option( 'recaptcha_privatekey' );
371
+ delete_option( 'recaptcha_flavor' );
372
+ delete_option( 'recaptcha_theme' );
373
+ restore_current_blog();
374
+ }
375
+ } else {
376
+ delete_option( 'recaptcha_publickey' );
377
+ delete_option( 'recaptcha_privatekey' );
378
 
379
+ delete_option( 'recaptcha_flavor' );
380
+ delete_option( 'recaptcha_theme' );
381
+ delete_option( 'recaptcha_enable_comments' );
382
+ delete_option( 'recaptcha_enable_signup' );
383
+ delete_option( 'recaptcha_enable_login' );
384
+ delete_option( 'recaptcha_disable_for_known_users' );
385
+ }
386
+ }
387
+
388
+ static function is_network_activated() {
389
+ if ( is_null(self::$_is_network_activated) ) {
390
+ if ( ! is_multisite() )
391
+ return false;
392
+ if ( ! function_exists( 'is_plugin_active_for_network' ) )
393
+ require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
394
+
395
+ self::$_is_network_activated = is_plugin_active_for_network( basename(dirname(__FILE__)).'/'.basename(__FILE__) );
396
+ }
397
+ return self::$_is_network_activated;
398
  }
399
  }
400
 
401
 
402
+ WP_reCaptcha::instance();
403
 
404
+ if ( is_admin() )
405
+ require_once dirname(__FILE__).'/inc/class-wp-recaptcha-options.php';