PluginProbe ʕ •ᴥ•ʔ
reCaptcha by BestWebSoft / 1.27
reCaptcha by BestWebSoft v1.27
1.79 1.80 1.82 1.83 1.84 1.85 1.86 1.87 trunk 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.10 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.18 1.19 1.20 1.21 1.22 1.23 1.24 1.25 1.26 1.27 1.28 1.29 1.30 1.31 1.32 1.33 1.34 1.35 1.36 1.37 1.38 1.39 1.40 1.41 1.42 1.43 1.44 1.45 1.46 1.47 1.48 1.49 1.50 1.51 1.52 1.53 1.54 1.55 1.56 1.57 1.58 1.59 1.60 1.61 1.62 1.63 1.64 1.65 1.66 1.67 1.68 1.70 1.71 1.72 1.73 1.74 1.75 1.78
google-captcha / google-captcha.php
google-captcha Last commit date
bws_menu 9 years ago css 9 years ago images 9 years ago includes 9 years ago js 9 years ago languages 9 years ago lib 9 years ago google-captcha.php 9 years ago readme.txt 9 years ago screenshot-1.png 9 years ago screenshot-2.png 9 years ago screenshot-3.png 9 years ago screenshot-4.png 9 years ago screenshot-5.png 9 years ago screenshot-6.png 9 years ago screenshot-7.png 9 years ago screenshot-8.png 9 years ago screenshot-9.png 9 years ago
google-captcha.php
1379 lines
1 <?php
2 /*
3 Plugin Name: Google Captcha (reCAPTCHA) by BestWebSoft
4 Plugin URI: http://bestwebsoft.com/products/wordpress/plugins/google-captcha/
5 Description: Protect WordPress website forms from spam entries with Google Captcha (reCaptcha).
6 Author: BestWebSoft
7 Text Domain: google-captcha
8 Domain Path: /languages
9 Version: 1.27
10 Author URI: http://bestwebsoft.com/
11 License: GPLv3 or later
12 */
13
14 /* © Copyright 2017 BestWebSoft ( http://support.bestwebsoft.com )
15
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License, version 2, as
18 published by the Free Software Foundation.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
29
30 /* Add menu page */
31 if ( ! function_exists( 'gglcptch_admin_menu' ) ) {
32 function gglcptch_admin_menu() {
33 bws_general_menu();
34 $gglcptch_settings = add_submenu_page( 'bws_panel', __( 'Google Captcha Settings', 'google-captcha' ), 'Google Captcha', 'manage_options', 'google-captcha.php', 'gglcptch_add_settings_page' );
35 add_action( 'load-' . $gglcptch_settings, 'gglcptch_add_tabs' );
36 }
37 }
38
39 if ( ! function_exists( 'gglcptch_plugins_loaded' ) ) {
40 function gglcptch_plugins_loaded() {
41 /* Internationalization, first(!) */
42 load_plugin_textdomain( 'google-captcha', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
43 }
44 }
45
46 if ( ! function_exists( 'gglcptch_init' ) ) {
47 function gglcptch_init() {
48 global $gglcptch_plugin_info, $gglcptch_options, $gglcptch_ip_in_whitelist;;
49
50 require_once( dirname( __FILE__ ) . '/bws_menu/bws_include.php' );
51 bws_include_init( plugin_basename( __FILE__ ) );
52
53 if ( empty( $gglcptch_plugin_info ) ) {
54 if ( ! function_exists( 'get_plugin_data' ) )
55 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
56 $gglcptch_plugin_info = get_plugin_data( __FILE__ );
57 }
58
59 /* Function check if plugin is compatible with current WP version */
60 bws_wp_min_version_check( plugin_basename( __FILE__ ), $gglcptch_plugin_info, '3.8' );
61
62 $is_admin = is_admin() && ! defined( 'DOING_AJAX' );
63 /* Call register settings function */
64 if ( ! $is_admin || ( isset( $_GET['page'] ) && 'google-captcha.php' == $_GET['page'] ) )
65 register_gglcptch_settings();
66
67 if ( empty( $gglcptch_ip_in_whitelist ) )
68 $gglcptch_ip_in_whitelist = gglcptch_whitelisted_ip();
69
70 /* Add hooks */
71 if ( ! $is_admin ) {
72 /* Add hooks */
73 if ( '1' == $gglcptch_options['login_form'] || '1' == $gglcptch_options['reset_pwd_form'] || '1' == $gglcptch_options['registration_form'] ) {
74 add_action( 'login_enqueue_scripts', 'gglcptch_add_styles' );
75
76 if ( '1' == $gglcptch_options['login_form'] ) {
77 add_action( 'login_form', 'gglcptch_login_display' );
78 if ( ! $gglcptch_ip_in_whitelist )
79 add_action( 'authenticate', 'gglcptch_login_check', 21, 1 );
80 }
81
82 if ( '1' == $gglcptch_options['reset_pwd_form'] ) {
83 add_action( 'lostpassword_form', 'gglcptch_login_display' );
84 if ( ! $gglcptch_ip_in_whitelist )
85 add_action( 'allow_password_reset', 'gglcptch_lostpassword_check' );
86 }
87
88 if ( '1' == $gglcptch_options['registration_form'] ) {
89 if ( ! is_multisite() ) {
90 add_action( 'register_form', 'gglcptch_login_display', 99 );
91 if ( ! $gglcptch_ip_in_whitelist )
92 add_action( 'registration_errors', 'gglcptch_lostpassword_check' );
93 } else {
94 add_action( 'signup_extra_fields', 'gglcptch_signup_display' );
95 add_action( 'signup_blogform', 'gglcptch_signup_display' );
96 if ( ! $gglcptch_ip_in_whitelist )
97 add_filter( 'wpmu_validate_user_signup', 'gglcptch_signup_check' );
98 }
99 }
100 }
101
102 if ( '1' == $gglcptch_options['comments_form'] ) {
103 add_action( 'comment_form_after_fields', 'gglcptch_commentform_display' );
104 add_action( 'comment_form_logged_in_after', 'gglcptch_commentform_display' );
105 if ( ! $gglcptch_ip_in_whitelist )
106 add_action( 'pre_comment_on_post', 'gglcptch_commentform_check' );
107 }
108
109 if ( '1' == $gglcptch_options['contact_form'] ) {
110 add_filter( 'cntctfrm_display_captcha', 'gglcptch_cf_display', 10, 2 );
111 if ( ! $gglcptch_ip_in_whitelist )
112 add_filter( 'cntctfrm_check_form', 'gglcptch_recaptcha_check' );
113 /**
114 * this filters are necessary for compatibility
115 * with old Contact Form Pro by BestWebsoft versions
116 * @deprecated since 1.0.4
117 * @todo remove after 25.02.2017
118 */
119 add_filter( 'cntctfrmpr_display_captcha', 'gglcptch_cf_display', 10, 2 );
120 if ( ! $gglcptch_ip_in_whitelist )
121 add_filter( 'cntctfrmpr_check_form', 'gglcptch_recaptcha_check' );
122 }
123 }
124 }
125 }
126
127 /**
128 * Activation plugin function
129 */
130 if ( ! function_exists( 'gglcptch_plugin_activate' ) ) {
131 function gglcptch_plugin_activate( $networkwide ) {
132 global $wpdb;
133 /* Activation function for network, check if it is a network activation - if so, run the activation function for each blog id */
134 if ( is_multisite() ) {
135 switch_to_blog( 1 );
136 register_uninstall_hook( __FILE__, 'gglcptch_delete_options' );
137 restore_current_blog();
138 } else {
139 register_uninstall_hook( __FILE__, 'gglcptch_delete_options' );
140 }
141 }
142 }
143
144 if ( ! function_exists( 'gglcptch_admin_init' ) ) {
145 function gglcptch_admin_init() {
146 global $bws_plugin_info, $gglcptch_plugin_info, $bws_shortcode_list;
147
148 if ( empty( $bws_plugin_info ) )
149 $bws_plugin_info = array( 'id' => '109', 'version' => $gglcptch_plugin_info["Version"] );
150
151 /* add google captcha to global $bws_shortcode_list */
152 $bws_shortcode_list['gglcptch'] = array( 'name' => 'Google Captcha (reCAPTCHA)' );
153 }
154 }
155
156 /* Add google captcha styles */
157 if ( ! function_exists( 'gglcptch_add_admin_script_styles' ) ) {
158 function gglcptch_add_admin_script_styles() {
159 if ( isset( $_REQUEST['page'] ) && 'google-captcha.php' == $_REQUEST['page'] ) {
160 wp_enqueue_style( 'gglcptch_stylesheet', plugins_url( 'css/style.css', __FILE__ ) );
161 wp_enqueue_script( 'gglcptch_admin_script', plugins_url( 'js/admin_script.js', __FILE__ ), array( 'jquery' ) );
162
163 if ( isset( $_GET['action'] ) && 'custom_code' == $_GET['action'] )
164 bws_plugins_include_codemirror();
165 }
166 }
167 }
168
169 /* Add google captcha admin styles for test key */
170 if ( ! function_exists( 'gglcptch_admin_footer' ) ) {
171 function gglcptch_admin_footer() {
172 if ( isset( $_REQUEST['page'] ) && 'google-captcha.php' == $_REQUEST['page'] ) {
173 /* for gglcptch test key */
174 global $gglcptch_options;
175 if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) {
176 $api_url = "https://www.google.com/recaptcha/api.js";
177 } else {
178 $api_url = "https://www.google.com/recaptcha/api/js/recaptcha_ajax.js";
179 }
180 wp_register_script( 'gglcptch_api', $api_url, false, false, true );
181 gglcptch_add_scripts();
182 }
183 }
184 }
185
186 /**
187 * Remove dublicate scripts
188 */
189 if ( ! function_exists( 'gglcptch_remove_dublicate_scripts' ) ) {
190 function gglcptch_remove_dublicate_scripts() {
191 global $wp_scripts;
192
193 if ( ! is_object( $wp_scripts ) || empty( $wp_scripts ) )
194 return false;
195
196 foreach ( $wp_scripts->registered as $script_name => $args ) {
197 if ( preg_match( "|google\.com/recaptcha/api\.js|", $args->src ) && 'gglcptch_api' != $script_name )
198 /* remove a previously enqueued script */
199 wp_dequeue_script( $script_name );
200 }
201 }
202 }
203
204 /**
205 * Add google captcha styles
206 */
207 if ( ! function_exists( 'gglcptch_add_styles' ) ) {
208 function gglcptch_add_styles() {
209 global $gglcptch_plugin_info, $gglcptch_options;
210 wp_enqueue_style( 'gglcptch', plugins_url( 'css/gglcptch.css', __FILE__ ), false, $gglcptch_plugin_info["Version"] );
211
212 if ( defined( 'BWS_ENQUEUE_ALL_SCRIPTS' ) && BWS_ENQUEUE_ALL_SCRIPTS ) {
213 if ( ! wp_script_is( 'gglcptch_api', 'registered' ) ) {
214 if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) {
215 $api_url = "https://www.google.com/recaptcha/api.js";
216 } else {
217 $api_url = "https://www.google.com/recaptcha/api/js/recaptcha_ajax.js";
218 }
219 wp_register_script( 'gglcptch_api', $api_url, false, false, true );
220 add_action( 'wp_footer', 'gglcptch_add_scripts' );
221 if (
222 '1' == $gglcptch_options['login_form'] ||
223 '1' == $gglcptch_options['reset_pwd_form'] ||
224 '1' == $gglcptch_options['registration_form']
225 )
226 add_action( 'login_footer', 'gglcptch_add_scripts' );
227 }
228 }
229 }
230 }
231
232 /**
233 * Add google captcha js scripts
234 */
235 if ( ! function_exists( 'gglcptch_add_scripts' ) ) {
236 function gglcptch_add_scripts() {
237 global $gglcptch_options;
238
239 if ( empty( $gglcptch_options ) )
240 register_gglcptch_settings();
241
242 if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] )
243 gglcptch_remove_dublicate_scripts();
244
245 wp_enqueue_script( 'gglcptch_script', plugins_url( 'js/script.js', __FILE__ ), array( 'jquery', 'gglcptch_api' ), false, true );
246
247 $version = $gglcptch_options['recaptcha_version'] == 'v2' ? '_v2' : '';
248
249 wp_localize_script( 'gglcptch_script', 'gglcptch', array(
250 'options' => array(
251 'version' => $gglcptch_options['recaptcha_version'],
252 'sitekey' => $gglcptch_options['public_key'],
253 'theme' => $gglcptch_options[ 'theme' . $version ],
254 'error' => "<strong>" . __( 'Warning', 'google-captcha' ) . ":</strong>&nbsp;" . __( 'It has been found more than one reCAPTCHA in current form. In this case reCAPTCHA will not work properly. Please remove all unnecessary reCAPTCHA blocks.', 'google-captcha' )
255 ),
256 'vars' => array(
257 'ajaxurl' => admin_url( 'admin-ajax.php' ),
258 'error_msg' => __( 'Error: You have entered an incorrect reCAPTCHA value', 'google-captcha' ),
259 'nonce' => wp_create_nonce( 'gglcptch_recaptcha_nonce' ),
260 'visibility' => ( 'login_footer' == current_filter() ) ? true : false
261 )
262 ) );
263 }
264 }
265
266 if ( ! function_exists( 'gglcptch_pagination_callback' ) ) {
267 function gglcptch_pagination_callback( $content ) {
268 $content .= "if ( typeof gglcptch !== 'undefined' ) { gglcptch.prepare(); }";
269 return $content;
270 }
271 }
272
273 /**
274 * Add the "async" attribute to our registered script.
275 */
276 if ( ! function_exists( 'gglcptch_add_async_attribute' ) ) {
277 function gglcptch_add_async_attribute( $tag, $handle ) {
278 if ( 'gglcptch_api' == $handle )
279 $tag = str_replace( ' src', ' data-cfasync="false" async="async" defer="defer" src', $tag );
280 return $tag;
281 }
282 }
283
284 if ( ! function_exists( 'gglcptch_create_table' ) ) {
285 function gglcptch_create_table() {
286 global $wpdb;
287 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
288 $whitelist_exist = $wpdb->query( "SHOW TABLES LIKE '{$wpdb->prefix}gglcptch_whitelist';" );
289 if ( ! $whitelist_exist ) {
290 $sql = "CREATE TABLE `{$wpdb->prefix}gglcptch_whitelist` (
291 `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
292 `ip` CHAR(31) NOT NULL,
293 `ip_from_int` BIGINT,
294 `ip_to_int` BIGINT,
295 `add_time` DATETIME,
296 PRIMARY KEY (`id`)
297 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
298 dbDelta( $sql );
299
300 /* add unique key */
301 if ( 0 == $wpdb->query( "SHOW KEYS FROM `{$wpdb->prefix}gglcptch_whitelist` WHERE Key_name='ip'" ) )
302 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}gglcptch_whitelist` ADD UNIQUE(`ip`);" );
303 }
304 }
305 }
306
307 /* Google catpcha settings */
308 if ( ! function_exists( 'register_gglcptch_settings' ) ) {
309 function register_gglcptch_settings() {
310 global $gglcptch_options, $bws_plugin_info, $gglcptch_plugin_info;
311
312 $plugin_db_version = '0.1';
313
314 /* Install the option defaults */
315 if ( ! get_option( 'gglcptch_options' ) )
316 add_option( 'gglcptch_options', gglcptch_get_default_options() );
317 /* Get options from the database */
318 $gglcptch_options = get_option( 'gglcptch_options' );
319
320 /* Array merge incase this version has added new options */
321 if ( ! isset( $gglcptch_options['plugin_option_version'] ) || $gglcptch_options['plugin_option_version'] != $gglcptch_plugin_info["Version"] ) {
322 $gglcptch_options = array_merge( gglcptch_get_default_options(), $gglcptch_options );
323 $gglcptch_options['plugin_option_version'] = $gglcptch_plugin_info["Version"];
324 /* show pro features */
325 $gglcptch_options['hide_premium_options'] = array();
326
327 if ( is_multisite() ) {
328 switch_to_blog( 1 );
329 register_uninstall_hook( __FILE__, 'gglcptch_delete_options' );
330 restore_current_blog();
331 } else {
332 register_uninstall_hook( __FILE__, 'gglcptch_delete_options' );
333 }
334 update_option( 'gglcptch_options', $gglcptch_options );
335 }
336 /* Update tables when update plugin and tables changes*/
337 if (
338 ! isset( $gglcptch_options['plugin_db_version'] ) ||
339 ( isset( $gglcptch_options['plugin_db_version'] ) && $gglcptch_options['plugin_db_version'] != $plugin_db_version )
340 ) {
341 if ( ! isset( $gglcptch_options['plugin_db_version'] ) ) {
342 gglcptch_create_table();
343 }
344 $gglcptch_options['plugin_db_version'] = $plugin_db_version;
345 update_option( 'gglcptch_options', $gglcptch_options );
346 }
347 }
348 }
349
350 if ( ! function_exists( 'gglcptch_get_default_options' ) ) {
351 function gglcptch_get_default_options() {
352 global $gglcptch_plugin_info;
353
354 $default_options = array(
355 'whitelist_message' => __( 'You are in the whitelist', 'google-captcha' ),
356 'public_key' => '',
357 'private_key' => '',
358 'login_form' => '1',
359 'registration_form' => '1',
360 'reset_pwd_form' => '1',
361 'comments_form' => '1',
362 'contact_form' => '0',
363 'theme' => 'red',
364 'theme_v2' => 'light',
365 'recaptcha_version' => 'v2',
366 'plugin_option_version' => $gglcptch_plugin_info["Version"],
367 'first_install' => strtotime( "now" ),
368 'display_settings_notice' => 1,
369 'suggest_feature_banner' => 1,
370 );
371
372 if ( function_exists( 'get_editable_roles' ) ) {
373 foreach ( get_editable_roles() as $role => $fields ) {
374 $default_options[ $role ] = '0';
375 }
376 }
377 return $default_options;
378 }
379 }
380
381 if ( ! function_exists( 'gglcptch_plugin_status' ) ) {
382 function gglcptch_plugin_status( $plugins, $all_plugins, $is_network ) {
383 $result = array(
384 'status' => '',
385 'plugin' => '',
386 'plugin_info' => array(),
387 );
388 foreach ( (array)$plugins as $plugin ) {
389 if ( array_key_exists( $plugin, $all_plugins ) ) {
390 if (
391 ( $is_network && is_plugin_active_for_network( $plugin ) ) ||
392 ( ! $is_network && is_plugin_active( $plugin ) )
393 ) {
394 $result['status'] = 'actived';
395 $result['plugin'] = $plugin;
396 $result['plugin_info'] = $all_plugins[$plugin];
397 break;
398 } else {
399 $result['status'] = 'deactivated';
400 $result['plugin'] = $plugin;
401 $result['plugin_info'] = $all_plugins[$plugin];
402 }
403
404 }
405 }
406 if ( empty( $result['status'] ) )
407 $result['status'] = 'not_installed';
408 return $result;
409 }
410 }
411
412 if ( ! function_exists( 'gglcptch_whitelisted_ip' ) ) {
413 function gglcptch_whitelisted_ip() {
414 global $wpdb, $gglcptch_options;
415 $checked = false;
416 if ( empty( $gglcptch_options ) )
417 $gglcptch_options = get_option( 'gglcptch_options' );
418 $whitelist_exist = $wpdb->query( "SHOW TABLES LIKE '{$wpdb->prefix}gglcptch_whitelist'" );
419 if ( 1 === $whitelist_exist ) {
420 $ip = '';
421 if ( isset( $_SERVER ) ) {
422 $server_vars = array( 'HTTP_X_REAL_IP', 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'REMOTE_ADDR' );
423 foreach( $server_vars as $var ) {
424 if ( isset( $_SERVER[ $var ] ) && ! empty( $_SERVER[ $var ] ) ) {
425 if ( filter_var( $_SERVER[ $var ], FILTER_VALIDATE_IP ) ) {
426 $ip = $_SERVER[ $var ];
427 break;
428 } else { /* if proxy */
429 $ip_array = explode( ',', $_SERVER[ $var ] );
430 if ( is_array( $ip_array ) && ! empty( $ip_array ) && filter_var( $ip_array[0], FILTER_VALIDATE_IP ) ) {
431 $ip = $ip_array[0];
432 break;
433 }
434 }
435 }
436 }
437 }
438
439 if ( ! empty( $ip ) ) {
440 $ip_int = sprintf( '%u', ip2long( $ip ) );
441 $result = $wpdb->get_var(
442 "SELECT `id`
443 FROM `{$wpdb->prefix}gglcptch_whitelist`
444 WHERE ( `ip_from_int` <= {$ip_int} AND `ip_to_int` >= {$ip_int} ) OR `ip` LIKE '{$ip}' LIMIT 1;"
445 );
446 $checked = is_null( $result ) || ! $result ? false : true;
447 } else {
448 $checked = false;
449 }
450 }
451 return $checked;
452 }
453 }
454
455 /* Display settings page */
456 if ( ! function_exists( 'gglcptch_add_settings_page' ) ) {
457 function gglcptch_add_settings_page() {
458 global $gglcptch_options, $gglcptch_plugin_info, $wp_version;
459 require_once( dirname( __FILE__ ) . '/includes/pro_banners.php' );
460
461 $plugin_basename = plugin_basename( __FILE__ );
462 $message = $error = '';
463
464 $all_plugins = get_plugins();
465 $is_network = is_multisite() && is_network_admin();
466 $is_main_site = is_main_site( get_current_blog_id() );
467 $admin_url = $is_network ? network_admin_url( '/' ) : admin_url( '/' );
468 $bws_contact_form = gglcptch_plugin_status( array( 'contact-form-plugin/contact_form.php', 'contact-form-pro/contact_form_pro.php' ), $all_plugins, $is_network );
469
470 if ( isset( $_POST['bws_hide_premium_options'] ) && check_admin_referer( $plugin_basename, 'gglcptch_nonce_name' ) ) {
471 $result = bws_hide_premium_options( $gglcptch_options );
472 $gglcptch_options = $result['options'];
473 update_option( 'gglcptch_options', $gglcptch_options );
474 }
475 if ( ! isset( $_GET['action'] ) ) {
476
477 $all_plugins = get_plugins();
478
479 /* Private and public keys */
480 $gglcptch_keys = array(
481 'public' => array(
482 'display_name' => __( 'Site key', 'google-captcha' ),
483 'form_name' => 'gglcptch_public_key',
484 'error_msg' => '',
485 ),
486 'private' => array(
487 'display_name' => __( 'Secret Key', 'google-captcha' ),
488 'form_name' => 'gglcptch_private_key',
489 'error_msg' => '',
490 ),
491 );
492
493 /* Checked forms */
494 $gglcptch_forms = array(
495 array( 'login_form', __( 'Login form', 'google-captcha' ) ),
496 array( 'registration_form', __( 'Registration form', 'google-captcha' ) ),
497 array( 'reset_pwd_form', __( 'Reset password form', 'google-captcha' ) ),
498 array( 'comments_form', __( 'Comments form', 'google-captcha' ) ),
499 );
500
501 /* Google captcha themes */
502 $gglcptch_themes = array(
503 array( 'red', 'Red' ),
504 array( 'white', 'White' ),
505 array( 'blackglass', 'Blackglass' ),
506 array( 'clean', 'Clean' ),
507 );
508
509 /* Save data for settings page */
510 if ( isset( $_POST['gglcptch_form_submit'] ) && check_admin_referer( $plugin_basename, 'gglcptch_nonce_name' ) ) {
511 if ( isset( $_POST['bws_hide_premium_options'] ) ) {
512 $hide_result = bws_hide_premium_options( $gglcptch_options );
513 $gglcptch_options = $hide_result['options'];
514 }
515
516 if ( ! $_POST['gglcptch_public_key'] || '' == $_POST['gglcptch_public_key'] ) {
517 $gglcptch_keys['public']['error_msg'] = __( 'Enter site key', 'google-captcha' );
518 $error = __( "WARNING: The captcha will not display while you don't fill key fields.", 'google-captcha' );
519 } else
520 $gglcptch_keys['public']['error_msg'] = '';
521
522 if ( ! $_POST['gglcptch_private_key'] || '' == $_POST['gglcptch_private_key'] ) {
523 $gglcptch_keys['private']['error_msg'] = __( 'Enter secret key', 'google-captcha' );
524 $error = __( "WARNING: The captcha will not display while you don't fill key fields.", 'google-captcha' );
525 } else
526 $gglcptch_keys['private']['error_msg'] = '';
527
528 if ( $_POST['gglcptch_public_key'] != $gglcptch_options['public_key'] || $_POST['gglcptch_private_key'] != $gglcptch_options['private_key'] )
529 $gglcptch_options['keys_verified'] = false;
530
531 $gglcptch_options['whitelist_message'] = stripslashes( esc_html( $_POST['gglcptch_whitelist_message'] ) );
532 $gglcptch_options['public_key'] = trim( stripslashes( esc_html( $_POST['gglcptch_public_key'] ) ) );
533 $gglcptch_options['private_key'] = trim( stripslashes( esc_html( $_POST['gglcptch_private_key'] ) ) );
534 $gglcptch_options['login_form'] = isset( $_POST['gglcptch_login_form'] ) ? 1 : 0;
535 $gglcptch_options['registration_form'] = isset( $_POST['gglcptch_registration_form'] ) ? 1 : 0;
536 $gglcptch_options['reset_pwd_form'] = isset( $_POST['gglcptch_reset_pwd_form'] ) ? 1 : 0;
537 $gglcptch_options['comments_form'] = isset( $_POST['gglcptch_comments_form'] ) ? 1 : 0;
538 $gglcptch_options['contact_form'] = isset( $_POST['gglcptch_contact_form'] ) ? 1 : 0;
539 $gglcptch_options['recaptcha_version'] = 'v1' == $_POST['gglcptch_recaptcha_version'] ? 'v1' : 'v2';
540 $gglcptch_options['theme'] = stripslashes( esc_html( $_POST['gglcptch_theme'] ) );
541 $gglcptch_options['theme_v2'] = stripslashes( esc_html( $_POST['gglcptch_theme_v2'] ) );
542
543 if ( function_exists( 'get_editable_roles' ) ) {
544 foreach ( get_editable_roles() as $role => $fields ) {
545 $gglcptch_options[ $role ] = isset( $_POST[ 'gglcptch_' . $role ] ) ? 1 : 0;
546 }
547 }
548
549 update_option( 'gglcptch_options', $gglcptch_options );
550 $message = __( 'Settings saved', 'google-captcha' );
551 }
552
553 if ( isset( $_REQUEST['bws_restore_confirm'] ) && check_admin_referer( $plugin_basename, 'bws_settings_nonce_name' ) ) {
554 $gglcptch_options = gglcptch_get_default_options();
555 update_option( 'gglcptch_options', $gglcptch_options );
556 $message = __( 'All plugin settings were restored', 'google-captcha' );
557 }
558 }
559
560 $bws_hide_premium_options_check = bws_hide_premium_options_check( $gglcptch_options );
561
562 /* GO PRO */
563 if ( isset( $_GET['action'] ) && 'go_pro' == $_GET['action'] ) {
564 $go_pro_result = bws_go_pro_tab_check( $plugin_basename, 'gglcptch_options' );
565 if ( ! empty( $go_pro_result['error'] ) )
566 $error = $go_pro_result['error'];
567 elseif ( ! empty( $go_pro_result['message'] ) )
568 $message = $go_pro_result['message'];
569 } ?>
570 <div class="wrap gglcptch_settings_page">
571 <h1 style="line-height: normal;"><?php _e( 'Google Captcha Settings', 'google-captcha' ); ?></h1>
572 <h2 class="nav-tab-wrapper">
573 <a class="nav-tab<?php if ( ! isset( $_GET['action'] ) ) echo ' nav-tab-active'; ?>" href="admin.php?page=google-captcha.php"><?php _e( 'Settings', 'google-captcha' ); ?></a>
574 <a class="nav-tab<?php if ( isset( $_GET['action'] ) && 'whitelist' == $_GET['action'] ) echo ' nav-tab-active'; ?>" href="admin.php?page=google-captcha.php&amp;action=whitelist"><?php _e( 'Whitelist', 'google-captcha' ); ?></a>
575 <a class="nav-tab <?php if ( isset( $_GET['action'] ) && 'custom_code' == $_GET['action'] ) echo ' nav-tab-active'; ?>" href="admin.php?page=google-captcha.php&amp;action=custom_code"><?php _e( 'Custom code', 'google-captcha' ); ?></a>
576 <a class="nav-tab<?php if ( isset( $_GET['action'] ) && 'go_pro' == $_GET['action'] ) echo ' nav-tab-active'; ?> bws_go_pro_tab" href="admin.php?page=google-captcha.php&amp;action=go_pro"><?php _e( 'Go PRO', 'google-captcha' ); ?></a>
577 </h2>
578 <?php if ( ! isset( $_GET['action'] ) && ! isset( $_REQUEST['bws_restore_default'] ) ) {
579 if ( $gglcptch_options['recaptcha_version'] == 'v1' ) {
580 printf( '<div id="gglcptch_v1_notice" class="updated inline"><p><strong>%s</strong></p></div>',
581 __( "Only one reCAPTCHA can be displayed on the page, it's related to reCAPTCHA version 1 features.", 'google-captcha' )
582 );
583 }
584 }
585 bws_show_settings_notice(); ?>
586 <div class="updated fade inline" <?php if ( "" == $message ) echo 'style="display:none"'; ?>><p><strong><?php echo $message; ?></strong></p></div>
587 <div class="error inline" <?php if ( "" == $error ) echo 'style="display:none"'; ?>><p><strong><?php echo $error; ?></strong></p></div>
588 <?php if ( ! empty( $hide_result['message'] ) ) { ?>
589 <div class="updated fade inline"><p><strong><?php echo $hide_result['message']; ?></strong></p></div>
590 <?php }
591 if ( ! isset( $_GET['action'] ) ) {
592 if ( isset( $_REQUEST['bws_restore_default'] ) && check_admin_referer( $plugin_basename, 'bws_settings_nonce_name' ) ) {
593 bws_form_restore_default_confirm( $plugin_basename );
594 } else { ?>
595 <div style="margin: 20px 0;">
596 <?php printf( __( "If you would like to add a Google Captcha (reCAPTCHA) to your page or post, please use %s button", 'google-captcha' ),
597 '<span class="bws_code"><img style="vertical-align: sub;" src="' . plugins_url( 'bws_menu/images/shortcode-icon.png', __FILE__ ) . '" alt=""/></span>'
598 ); ?>
599 <div class="bws_help_box bws_help_box_right dashicons dashicons-editor-help" style="vertical-align: middle;">
600 <div class="bws_hidden_help_text" style="min-width: 260px;">
601 <?php printf(
602 __( "You can add the Google Captcha (reCAPTCHA) to your page or post by clicking on %s button in the content edit block using the Visual mode. If the button isn't displayed or you would like to add the Google Captcha (reCAPTCHA) to your own form , please use the shortcode %s", 'google-captcha' ),
603 '<code><img style="vertical-align: sub;" src="' . plugins_url( 'bws_menu/images/shortcode-icon.png', __FILE__ ) . '" alt="" /></code>',
604 sprintf( '<span class="bws_code">[bws_google_captcha]</span><br/>' )
605 ); ?>
606 </div>
607 </div>
608 </div>
609 <form id="gglcptch_admin_settings_page" class="bws_form" method="post" action="admin.php?page=google-captcha.php">
610 <h3><?php _e( 'Authentication', 'google-captcha' ); ?></h3>
611 <p><?php printf( __( 'Before you are able to do something, you must to register %shere%s', 'google-captcha' ), '<a target="_blank" href="https://www.google.com/recaptcha/admin#list">','</a>.' ); ?></p>
612 <p><?php _e( 'Enter site key and secret key, that you get after registration', 'google-captcha' ); ?></p>
613 <table id="gglcptch-keys" class="form-table">
614 <?php foreach ( $gglcptch_keys as $key => $fields ) { ?>
615 <tr valign="top">
616 <th scope="row"><?php echo $fields['display_name']; ?></th>
617 <td>
618 <input type="text" name="<?php echo $fields['form_name']; ?>" value="<?php echo $gglcptch_options[ $key . '_key' ] ?>" maxlength="200" />
619 <label class="gglcptch_error_msg error"><?php echo $fields['error_msg']; ?></label>
620 <span class="dashicons dashicons-yes gglcptch_verified <?php if ( ! isset( $gglcptch_options['keys_verified'] ) || true !== $gglcptch_options['keys_verified'] ) echo 'hidden'; ?>"></span>
621 </td>
622 </tr>
623 <?php } ?>
624 </table>
625 <?php if ( ! empty( $gglcptch_options['public_key'] ) && ! empty( $gglcptch_options['private_key'] ) ) { ?>
626 <p id="gglcptch-test-keys" class="submit hide-if-no-js">
627 <a class="button button-secondary" href="<?php echo add_query_arg( array( '_wpnonce' => wp_create_nonce( 'gglcptch-test-keys' ) , 'action' => 'gglcptch-test-keys' ), admin_url( 'admin-ajax.php' ) ); ?>"><?php _e( 'Test Keys' , 'google-captcha' ); ?></a>
628 </p>
629 <?php } ?>
630 <h3><?php _e( 'Options', 'google-captcha' ); ?></h3>
631 <table class="form-table">
632 <tr valign="top">
633 <th scope="row"><?php _e( 'Enable reCAPTCHA for', 'google-captcha' ); ?></th>
634 <td>
635 <fieldset>
636 <p>
637 <i><?php _e( 'WordPress default', 'google-captcha' ); ?></i>
638 </p>
639 <?php foreach ( $gglcptch_forms as $form ) {
640 $gglcptch_form_type = $form[0];
641 $gglcptch_form_name = $form[1];
642 $gglcptch_form_attr = ( '1' == $gglcptch_options[ $gglcptch_form_type ] ) ? 'checked="checked"' : '';
643 $gglcptch_form_notice = '';
644
645 if ( ( $gglcptch_form_type == 'registration_form' || $gglcptch_form_type == 'reset_pwd_form' ) && ! $is_main_site ) {
646 $gglcptch_form_notice .= sprintf( '<span class="bws_info">%s</span>', __( 'This option is available only for network or for main blog', 'google-captcha' ) );
647 $gglcptch_form_attr = 'disabled="disabled" readonly="readonly"';
648 } ?>
649 <label><input type="checkbox" name="<?php echo 'gglcptch_' . $gglcptch_form_type; ?>" value="<?php echo $gglcptch_form_type; ?>" <?php echo $gglcptch_form_attr; ?> /> <?php echo $gglcptch_form_name; ?></label>
650 <div class="bws_help_box dashicons dashicons-editor-help" style="vertical-align: middle;"><div class="bws_hidden_help_text"><img src="<?php echo plugins_url( 'google-captcha/images') . '/' . $gglcptch_form_type; ?>.jpg" title="<?php echo $gglcptch_form_name; ?>" alt="<?php echo $gglcptch_form_name; ?>"></div></div> <?php echo $gglcptch_form_notice; ?><br />
651 <?php } ?>
652 <br />
653 <p>
654 <i><?php _e( 'Plugins', 'google-captcha' ); ?></i>
655 </p>
656 <?php /* Check Contact Form by BestWebSoft */
657 $gglcptch_plugin = $bws_contact_form;
658 $gglcptch_plugin_name = 'Contact Form by BestWebSoft';
659 $gglcptch_attrs = $gglcptch_plugin_notice = '';
660 if ( 'deactivated' == $gglcptch_plugin['status'] ) {
661 $gglcptch_attrs = 'disabled="disabled"';
662 $gglcptch_plugin_notice = sprintf( __( 'You should %s to use this functionality', 'google-captcha' ),
663 sprintf( '<a href="%splugins.php">%s%s %s</a>', $admin_url, __( 'activate', 'google-captcha' ), ( is_network_admin() ? ' ' . __( 'for network', 'google-captcha' ) : '' ), $gglcptch_plugin_name )
664 );
665 } elseif ( 'not_installed' == $gglcptch_plugin['status'] ) {
666 $gglcptch_attrs = 'disabled="disabled"';
667 $gglcptch_plugin_notice = sprintf( __( 'You should %s to use this functionality', 'google-captcha' ),
668 sprintf( '<a href="http://bestwebsoft.com/products/wordpress/plugins/contact-form/?k=0a750deb99a8e5296a5432f4c9cb9b55&pn=75&v=%s&wp_v=%s">%s %s</a>', $gglcptch_plugin_info["Version"], $wp_version, __( 'download', 'google-captcha' ), $gglcptch_plugin_name )
669 );
670 }
671 if ( $gglcptch_attrs == '' && ( is_plugin_active( 'contact-form-multi-pro/contact-form-multi-pro.php' ) || is_plugin_active( 'contact-form-multi/contact-form-multi.php' ) ) )
672 $gglcptch_plugin_notice = ' (' . __( 'Check off for adding captcha to forms on their settings pages', 'google-captcha' ) . ')';
673
674 if ( '1' == $gglcptch_options['contact_form'] && $gglcptch_attrs == '' ) {
675 $gglcptch_attrs .= ' checked="checked"';
676 } ?>
677 <label><input type="checkbox" <?php echo $gglcptch_attrs; ?> name="gglcptch_contact_form" value="contact_form" /> <?php echo $gglcptch_plugin_name; ?></label>
678 <div class="bws_help_box dashicons dashicons-editor-help" style="vertical-align: middle;"><div class="bws_hidden_help_text"><img src="<?php echo plugins_url( 'google-captcha/images'); ?>/contact_form.jpg" title="<?php echo $gglcptch_plugin_name; ?>" alt="<?php echo $gglcptch_plugin_name; ?>"></div></div>
679 <span class="bws_info"><?php echo $gglcptch_plugin_notice; ?></span><br />
680 <?php gglcptch_pro_block( 'gglcptch_supported_plugins_banner' ); ?>
681 <span class="bws_info"><?php printf( __( 'If you would like to add Google Captcha (reCAPTCHA) to a custom form see %s', 'google-captcha' ), sprintf( '<a href="http://bestwebsoft.com/products/wordpress/plugins/google-captcha/faq/" target="_blank">%s</a>', __( 'FAQ', 'google-captcha' ) ) ); ?></span>
682 </fieldset>
683 </td>
684 </tr>
685 <tr valign="top">
686 <th scope="row"><?php _e( 'Hide reCAPTCHA in Comments form for', 'google-captcha' ); ?></th>
687 <td>
688 <fieldset>
689 <?php if ( function_exists( 'get_editable_roles' ) ) {
690 foreach ( get_editable_roles() as $role => $fields) : ?>
691 <label><input type="checkbox" name="<?php echo 'gglcptch_' . $role; ?>" value=<?php echo $role; if ( isset( $gglcptch_options[ $role ] ) && '1' == $gglcptch_options[ $role ] ) echo ' checked'; ?>> <?php echo $fields['name']; ?></label><br/>
692 <?php endforeach;
693 } ?>
694 </fieldset>
695 </td>
696 </tr>
697 <tr valign="top">
698 <th scope="row"><?php _e( 'Whitelist notification', 'google-captcha' ); ?></th>
699 <td>
700 <label>
701 <input type="text" id="gglcptch_whitelist_message" name="gglcptch_whitelist_message" value="<?php echo $gglcptch_options['whitelist_message']; ?>">
702 <div class="bws_help_box dashicons dashicons-editor-help" style="vertical-align: middle;">
703 <div class="bws_hidden_help_text" style="min-width: 260px;">
704 <?php _e( 'This message will be displayed instead of the reCAPTCHA If the user IP is added to the whitelist', 'google-captcha' ); ?>
705 </div>
706 </div><div class="clear"></div>
707 </label>
708 </td>
709 </tr>
710 <tr valign="top">
711 <th scope="row"><?php _e( 'reCAPTCHA version', 'google-captcha' ); ?></th>
712 <td>
713 <fieldset>
714 <label><input type="radio" name="gglcptch_recaptcha_version" value="v1"<?php if ( 'v1' == $gglcptch_options['recaptcha_version'] ) echo ' checked="checked"'; ?>> <?php _e( 'version', 'google-captcha' ); ?> 1</label>
715 <div class="bws_help_box dashicons dashicons-editor-help" style="vertical-align: middle;"><div class="bws_hidden_help_text"><img src="<?php echo plugins_url( 'google-captcha/images'); ?>/recaptcha_v1.png" title="reCAPTCHA <?php _e( 'version', 'google-captcha' ); ?> 1" alt="reCAPTCHA <?php _e( 'version', 'google-captcha' ); ?> 1"></div></div><br/>
716 <label><input type="radio" name="gglcptch_recaptcha_version" value="v2"<?php if ( 'v2' == $gglcptch_options['recaptcha_version'] ) echo ' checked="checked"'; ?>> <?php _e( 'version', 'google-captcha' ); ?> 2</label>
717 <div class="bws_help_box dashicons dashicons-editor-help" style="vertical-align: middle;"><div class="bws_hidden_help_text"><img src="<?php echo plugins_url( 'google-captcha/images'); ?>/recaptcha_v2.png" title="reCAPTCHA <?php _e( 'version', 'google-captcha' ); ?> 2" alt="reCAPTCHA <?php _e( 'version', 'google-captcha' ); ?> 2"></div></div>
718 </fieldset>
719 </td>
720 </tr>
721 <tr class="gglcptch_theme_v1" valign="top">
722 <th scope="row">
723 <?php _e( 'reCAPTCHA theme', 'google-captcha' ); ?>
724 <br/><span class="bws_info">(<?php _e( 'for version', 'google-captcha' ); ?> 1)</span>
725 </th>
726 <td>
727 <select name="gglcptch_theme">
728 <?php foreach ( $gglcptch_themes as $theme ) : ?>
729 <option value=<?php echo $theme[0]; if ( $theme[0] == $gglcptch_options['theme'] ) echo ' selected'; ?>> <?php echo $theme[1]; ?></option>
730 <?php endforeach; ?>
731 </select>
732 </td>
733 </tr>
734 <tr class="gglcptch_theme_v2" valign="top">
735 <th scope="row">
736 <?php _e( 'reCAPTCHA theme', 'google-captcha' ); ?>
737 <br/><span class="bws_info">(<?php _e( 'for version', 'google-captcha' ); ?> 2)</span>
738 </th>
739 <td>
740 <select name="gglcptch_theme_v2">
741 <option value="light" <?php if ( 'light' == $gglcptch_options['theme_v2'] ) echo ' selected'; ?>>light</option>
742 <option value="dark" <?php if ( 'dark' == $gglcptch_options['theme_v2'] ) echo ' selected'; ?>>dark</option>
743 </select>
744 </td>
745 </tr>
746 </table>
747 <?php gglcptch_pro_block( 'gglcptch_additional_settings_banner' ); ?>
748 <p class="submit">
749 <input id="bws-submit-button" type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'google-captcha' ); ?>" name="gglcptch_save_changes" />
750 <input type="hidden" name="gglcptch_form_submit" value="submit" />
751 <?php wp_nonce_field( $plugin_basename, 'gglcptch_nonce_name' ); ?>
752 </p>
753 </form>
754 <?php bws_form_restore_default_settings( $plugin_basename );
755 }
756 } elseif ( 'whitelist' == $_GET['action'] ) {
757 require_once( dirname( __FILE__ ) . '/includes/whitelist.php' );
758 $page = new Gglcptch_Whitelist( $plugin_basename );
759 if ( is_object( $page ) )
760 $page->display_content();
761 } elseif ( 'custom_code' == $_GET['action'] ) {
762 bws_custom_code_tab();
763 } elseif ( 'go_pro' == $_GET['action'] ) {
764 bws_go_pro_tab_show( $bws_hide_premium_options_check, $gglcptch_plugin_info, $plugin_basename, 'google-captcha.php', 'google-captcha-pro.php', 'google-captcha-pro/google-captcha-pro.php', 'google-captcha', 'b850d949ccc1239cab0da315c3c822ab', '109', isset( $go_pro_result['pro_plugin_is_activated'] ) );
765 }
766 bws_plugin_reviews_block( $gglcptch_plugin_info['Name'], 'google-captcha' ); ?>
767 </div>
768 <?php }
769 }
770
771 /* Checking current user role */
772 if ( ! function_exists( 'gglcptch_check_role' ) ) {
773 function gglcptch_check_role() {
774 global $current_user, $gglcptch_options;
775
776 if ( ! is_user_logged_in() )
777 return false;
778
779 if ( ! empty( $current_user->roles[0] ) ) {
780 $role = $current_user->roles[0];
781 if ( empty( $gglcptch_options ) )
782 register_gglcptch_settings();
783 return isset( $gglcptch_options[ $role ] ) && '1' == $gglcptch_options[ $role ] ? true : false;
784 } else
785 return false;
786 }
787 }
788
789 /* Display google captcha via shortcode */
790 if ( ! function_exists( 'gglcptch_display' ) ) {
791 function gglcptch_display( $content = false ) {
792 global $gglcptch_options, $gglcptch_count, $gglcptch_ip_in_whitelist;
793
794 if ( empty( $gglcptch_options ) )
795 register_gglcptch_settings();
796
797 if ( empty( $gglcptch_ip_in_whitelist ) )
798 $gglcptch_ip_in_whitelist = gglcptch_whitelisted_ip();
799
800 if ( ! $gglcptch_ip_in_whitelist ) {
801
802 if ( ! $gglcptch_count )
803 $gglcptch_count = 1;
804
805 $publickey = $gglcptch_options['public_key'];
806 $privatekey = $gglcptch_options['private_key'];
807
808 $content .= '<div class="gglcptch gglcptch_' . $gglcptch_options['recaptcha_version'] . '">';
809 if ( ! $privatekey || ! $publickey ) {
810 if ( current_user_can( 'manage_options' ) ) {
811 $content .= sprintf(
812 '<strong>%s <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s <a target="_blank" href="%s">%s</a>.</strong>',
813 __( 'To use Google Captcha you must get the keys from', 'google-captcha' ),
814 __( 'here', 'google-captcha' ),
815 __( 'and enter them on the', 'google-captcha' ),
816 admin_url( '/admin.php?page=google-captcha.php' ),
817 __( 'plugin setting page', 'google-captcha' )
818 );
819 }
820 $content .= '</div>';
821 $gglcptch_count++;
822 return $content;
823 }
824
825 /* generating random id value in case of getting content with pagination plugin for not getting duplicate id values */
826 $id = mt_rand();
827 if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) {
828 $content .= '<div id="gglcptch_recaptcha_' . $id . '" class="gglcptch_recaptcha"></div>
829 <noscript>
830 <div style="width: 302px;">
831 <div style="width: 302px; height: 422px; position: relative;">
832 <div style="width: 302px; height: 422px; position: absolute;">
833 <iframe src="https://www.google.com/recaptcha/api/fallback?k=' . $publickey . '" frameborder="0" scrolling="no" style="width: 302px; height:422px; border-style: none;"></iframe>
834 </div>
835 </div>
836 <div style="border-style: none; bottom: 12px; left: 25px; margin: 0px; padding: 0px; right: 25px; background: #f9f9f9; border: 1px solid #c1c1c1; border-radius: 3px; height: 60px; width: 300px;">
837 <textarea id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px !important; height: 40px !important; border: 1px solid #c1c1c1 !important; margin: 10px 25px !important; padding: 0px !important; resize: none !important;"></textarea>
838 </div>
839 </div>
840 </noscript>';
841 $api_url = "https://www.google.com/recaptcha/api.js";
842 } else {
843 require_once( 'lib/recaptchalib.php' );
844 $content .= '<div id="gglcptch_recaptcha_' . $id . '" class="gglcptch_recaptcha"></div>';
845 $content .= gglcptch_recaptcha_get_html( $publickey, null, is_ssl() );
846 $api_url = "https://www.google.com/recaptcha/api/js/recaptcha_ajax.js";
847 }
848 $content .= '</div>';
849 $gglcptch_count++;
850
851 /* register reCAPTCHA script */
852 if ( ! wp_script_is( 'gglcptch_api', 'registered' ) ) {
853 wp_register_script( 'gglcptch_api', $api_url, false, false, true );
854 add_action( 'wp_footer', 'gglcptch_add_scripts' );
855 if (
856 '1' == $gglcptch_options['login_form'] ||
857 '1' == $gglcptch_options['reset_pwd_form'] ||
858 '1' == $gglcptch_options['registration_form']
859 )
860 add_action( 'login_footer', 'gglcptch_add_scripts' );
861 }
862 } else {
863 if ( ! empty( $gglcptch_options['whitelist_message'] ) )
864 $content .= '<label class="gglcptch_whitelist_message">' . $gglcptch_options['whitelist_message'] . '</label>';
865 }
866
867 return $content;
868 }
869 }
870
871 if ( ! function_exists( 'gglcptch_get_response' ) ) {
872 function gglcptch_get_response( $privatekey, $remote_ip ) {
873 $args = array(
874 'body' => array(
875 'secret' => $privatekey,
876 'response' => stripslashes( esc_html( $_POST["g-recaptcha-response"] ) ),
877 'remoteip' => $remote_ip,
878 ),
879 'sslverify' => false
880 );
881 $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $args );
882 return json_decode( wp_remote_retrieve_body( $resp ), true );
883 }
884 }
885
886 /* Check google captcha */
887 if ( ! function_exists( 'gglcptch_check' ) ) {
888 function gglcptch_check( $debug = false ) {
889 global $gglcptch_options;
890
891 if ( empty( $gglcptch_options ) )
892 register_gglcptch_settings();
893
894 $publickey = $gglcptch_options['public_key'];
895 $privatekey = $gglcptch_options['private_key'];
896
897 if ( ! $privatekey || ! $publickey ) {
898 return array(
899 'response' => false,
900 'reason' => 'ERROR_NO_KEYS'
901 );
902 }
903
904 $gglcptch_remote_addr = filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP );
905
906 if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) {
907
908 if ( ! isset( $_POST["g-recaptcha-response"] ) ) {
909 return array(
910 'response' => false,
911 'reason' => 'RECAPTCHA_NO_RESPONSE'
912 );
913 } elseif ( empty( $_POST["g-recaptcha-response"] ) ) {
914 return array(
915 'response' => false,
916 'reason' => 'RECAPTCHA_EMPTY_RESPONSE'
917 );
918 }
919
920 $response = gglcptch_get_response( $privatekey, $gglcptch_remote_addr );
921
922 if ( isset( $response['success'] ) && !! $response['success'] ) {
923 return array(
924 'response' => true,
925 'reason' => ''
926 );
927 } else {
928 return array(
929 'response' => false,
930 'reason' => $debug ? $response['error-codes'] : 'VERIFICATION_FAILED'
931 );
932 }
933 } else {
934 $gglcptch_recaptcha_challenge_field = $gglcptch_recaptcha_response_field = '';
935
936 if ( ! isset( $_POST['recaptcha_challenge_field'] ) && ! isset( $_POST['recaptcha_response_field'] ) ) {
937 return array(
938 'response' => false,
939 'reason' => 'RECAPTCHA_NO_RESPONSE'
940 );
941 } elseif ( ! empty( $_POST['recaptcha_challenge_field'] ) && empty( $_POST['recaptcha_response_field'] ) ) {
942 return array(
943 'response' => false,
944 'reason' => 'RECAPTCHA_EMPTY_RESPONSE'
945 );
946 } else {
947 $gglcptch_recaptcha_challenge_field = stripslashes( esc_html( $_POST['recaptcha_challenge_field'] ) );
948 $gglcptch_recaptcha_response_field = stripslashes( esc_html( $_POST['recaptcha_response_field'] ) );
949 }
950
951 require_once( 'lib/recaptchalib.php' );
952 $response = gglcptch_recaptcha_check_answer( $privatekey, $gglcptch_remote_addr, $gglcptch_recaptcha_challenge_field, $gglcptch_recaptcha_response_field );
953
954 if ( ! $response->is_valid ) {
955 return array(
956 'response' => false,
957 'reason' => $debug ? $response->error : 'VERIFICATION_FAILED'
958 );
959 } else {
960 return array(
961 'response' => true,
962 'reason' => ''
963 );
964 }
965 }
966 }
967 }
968
969 /* Add google captcha to the login form */
970 if ( ! function_exists( 'gglcptch_login_display' ) ) {
971 function gglcptch_login_display() {
972 global $gglcptch_options;
973 if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) {
974 $from_width = 302;
975 } else {
976 $from_width = 320;
977 if ( 'clean' == $gglcptch_options['theme'] )
978 $from_width = 450;
979 } ?>
980 <style type="text/css" media="screen">
981 .login-action-login #loginform,
982 .login-action-lostpassword #lostpasswordform,
983 .login-action-register #registerform {
984 width: <?php echo $from_width; ?>px !important;
985 }
986 #login_error,
987 .message {
988 width: <?php echo $from_width + 20; ?>px !important;
989 }
990 .login-action-login #loginform .gglcptch,
991 .login-action-lostpassword #lostpasswordform .gglcptch,
992 .login-action-register #registerform .gglcptch {
993 margin-bottom: 10px;
994 }
995 </style>
996 <?php echo gglcptch_display();
997 return true;
998 }
999 }
1000
1001 /* Check google captcha in login form */
1002 if ( ! function_exists( 'gglcptch_login_check' ) ) {
1003 function gglcptch_login_check( $user ) {
1004
1005 $result = gglcptch_check();
1006
1007 if ( ! $result['response'] ) {
1008 if ( $result['reason'] == 'ERROR_NO_KEYS' ) {
1009 return $user;
1010 }
1011
1012 $error_message = sprintf( '<strong>%s</strong>: %s', __( 'Error', 'google-captcha' ), __( 'You have entered an incorrect reCAPTCHA value', 'google-captcha' ) );
1013
1014 if ( $result['reason'] == 'VERIFICATION_FAILED' ) {
1015 wp_clear_auth_cookie();
1016 return new WP_Error( 'gglcptch_error', $error_message );
1017 }
1018
1019 if ( isset( $_REQUEST['log'] ) && isset( $_REQUEST['pwd'] ) ) {
1020 return new WP_Error( 'gglcptch_error', $error_message );
1021 } else {
1022 return $user;
1023 }
1024 } else {
1025 return $user;
1026 }
1027 }
1028 }
1029
1030 /* Check google captcha in BWS Contact Form */
1031 if ( ! function_exists( 'gglcptch_recaptcha_check' ) ) {
1032 function gglcptch_recaptcha_check( $allow = true ) {
1033 /**
1034 * this condition is necessary for compatibility
1035 * with Contact Form ( Free and Pro ) by BestWebsoft plugins versions
1036 * that use $_POST as parameter for hook ( old versions )
1037 * apply_filters( 'cntctfrmpr_check_form', $_POST );
1038 * @deprecated since 1.22
1039 * @todo remove after 25.02.2017
1040 */
1041 if ( is_array( $allow ) ) {
1042 $allow = false;
1043 $old_cf_version = true;
1044 } else /* end @todo */ if ( ! $allow || is_string( $allow ) || is_wp_error( $allow ) ) {
1045 return $allow;
1046 }
1047
1048 $result = gglcptch_check();
1049
1050 if ( $result['response'] || $result['reason'] == 'ERROR_NO_KEYS' )
1051 return true;
1052
1053 /**
1054 * @deprecated since 1.22
1055 * @todo remove after 25.02.2017
1056 */
1057 if ( isset( $old_cf_version ) ) {
1058 return false;
1059 } else /* end @todo */ {
1060 $error_message = '<strong>' . __( 'Error', 'google-captcha' ) . '</strong>:&nbsp;' . __( 'You have entered an incorrect reCAPTCHA value', 'google-captcha' );
1061 /**
1062 * Function 'cntctfrm_handle_captcha_filters' was added in Contact Form 4.0.2 (Free and Pro)
1063 * remove this condition. WP_Error is correct object for return.
1064 * @deprecated since 1.26
1065 * @todo remove after 01.08.2017
1066 */
1067 if ( function_exists( 'cntctfrm_handle_captcha_filters' ) ) {
1068 $allow = new WP_Error();
1069 $allow->add( 'gglcptch_error', $error_message );
1070 } else {
1071 $allow = $error_message;
1072 }
1073 }
1074 return $allow;
1075 }
1076 }
1077
1078 /* Check google captcha in lostpassword form */
1079 if ( ! function_exists( 'gglcptch_lostpassword_check' ) ) {
1080 function gglcptch_lostpassword_check( $allow ) {
1081
1082 $result = gglcptch_check();
1083
1084 if ( $result['response'] || $result['reason'] == 'ERROR_NO_KEYS' )
1085 return $allow;
1086
1087 if ( ! is_wp_error( $allow ) )
1088 $allow = new WP_Error();
1089
1090 $allow->add( 'gglcptch_error', '<strong>' . __( 'ERROR', 'google-captcha' ) . '</strong>:&nbsp;' . __( 'You have entered an incorrect reCAPTCHA value', 'google-captcha' ) . '.' );
1091 return $allow;
1092 }
1093 }
1094
1095 /* Add google captcha to the multisite login form */
1096 if ( ! function_exists( 'gglcptch_signup_display' ) ) {
1097 function gglcptch_signup_display( $errors ) {
1098 if ( $error_message = $errors->get_error_message( 'gglcptch_error' ) ) {
1099 printf( '<p class="error gglcptch_error">%s</p>', $error_message );
1100 }
1101 echo gglcptch_display();
1102 }
1103 }
1104
1105 /* Check google captcha in multisite login form */
1106 if ( ! function_exists( 'gglcptch_signup_check' ) ) {
1107 function gglcptch_signup_check( $result ) {
1108 global $current_user;
1109
1110 if ( is_admin() && ! defined( 'DOING_AJAX' ) && ! empty( $current_user->data->ID ) )
1111 return $result;
1112
1113 $check_result = gglcptch_check();
1114
1115 if ( $check_result['response'] || $check_result['reason'] == 'ERROR_NO_KEYS' )
1116 return $result;
1117
1118 $error = $result['errors'];
1119 $error->add( 'gglcptch_error', '<strong>' . __( 'ERROR', 'google-captcha' ) . '</strong>:&nbsp;' . __( 'You have entered an incorrect reCAPTCHA value', 'google-captcha' ) . '.' );
1120 return $result;
1121 }
1122 }
1123
1124 /* Add google captcha to the comment form */
1125 if ( ! function_exists( 'gglcptch_commentform_display' ) ) {
1126 function gglcptch_commentform_display() {
1127 if ( gglcptch_check_role() )
1128 return;
1129 echo gglcptch_display();
1130 return true;
1131 }
1132 }
1133
1134 /* Check JS enabled for comment form */
1135 if ( ! function_exists( 'gglcptch_commentform_check' ) ) {
1136 function gglcptch_commentform_check() {
1137 if ( gglcptch_check_role() )
1138 return;
1139
1140 $result = gglcptch_check();
1141
1142 if ( $result['response'] || $result['reason'] == 'ERROR_NO_KEYS' )
1143 return;
1144
1145 wp_die( '<strong>' . __( 'ERROR', 'google-captcha' ) . '</strong>:&nbsp;' . __( 'You have entered an incorrect reCAPTCHA value. Click the BACK button on your browser, and try again.', 'google-captcha' ) );
1146 }
1147 }
1148
1149 /* display google captcha in Contact form */
1150 if ( ! function_exists( 'gglcptch_cf_display' ) ) {
1151 function gglcptch_cf_display( $content, $form_slug = "" ) {
1152 /**
1153 * this are necessary for compatibility
1154 * with old Contact Form Free and Pro by BestWebsoft versions.
1155 * correct return - $content = $content . gglcptch_display();
1156 * @since 1.26
1157 * @todo remove after 1.03.2017
1158 */
1159 if ( is_string( $content ) )
1160 $content = $content . gglcptch_display();
1161 elseif ( is_array( $content ) )
1162 $content = gglcptch_display();
1163 else
1164 $content = $form_slug . gglcptch_display();
1165
1166 return $content;
1167 }
1168 }
1169
1170 /* Check Google Captcha in shortcode and contact form */
1171 if ( ! function_exists( 'gglcptch_captcha_check' ) ) {
1172 function gglcptch_captcha_check() {
1173 $result = gglcptch_check();
1174 echo $result['response'] ? "success" : "error";
1175 die();
1176 }
1177 }
1178
1179 if ( ! function_exists( 'gglcptch_test_keys' ) ) {
1180 function gglcptch_test_keys() {
1181 if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'] , $_REQUEST['action'] ) ) {
1182 header( 'Content-Type: text/html' ); ?>
1183 <p><?php _e( 'Please, complete the captcha and submit "Test verification"', 'google-captcha' ); ?></p>
1184 <?php echo gglcptch_display(); ?>
1185 <p>
1186 <input type="hidden" name="gglcptch_test_keys_verification-nonce" value="<?php echo wp_create_nonce( 'gglcptch_test_keys_verification' ); ?>" />
1187 <button id="gglcptch_test_keys_verification" name="action" class="button-primary" value="gglcptch_test_keys_verification"><?php _e( 'Test verification', 'google-captcha' ); ?></button>
1188 </p>
1189 <?php }
1190 die();
1191 }
1192 }
1193
1194 if ( ! function_exists( 'gglcptch_test_keys_verification' ) ) {
1195 function gglcptch_test_keys_verification() {
1196 if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'] , $_REQUEST['action'] ) ) {
1197 $result = gglcptch_check( true );
1198
1199 if ( ! $result['response'] ) {
1200 $errors = array(
1201 /* custom error */
1202 'RECAPTCHA_EMPTY_RESPONSE' => __( 'The user response was missing', 'google-captcha' ),
1203 /* v2 error */
1204 'missing-input-secret' => __( 'The Secret Key is missing', 'google-captcha' ),
1205 'invalid-input-secret' => sprintf(
1206 '<strong>%s</strong>. <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s.',
1207 __( 'The Secret Key is invalid', 'google-captcha' ),
1208 __( 'Check your domain configuration', 'google-captcha' ),
1209 __( 'and enter it again', 'google-captcha' )
1210 ),
1211 'missing-input-response' => __( 'The user response was missing', 'google-captcha' ),
1212 'invalid-input-response' => __( 'The user response is invalid', 'google-captcha' ),
1213 /* v1 error */
1214 'invalid-site-private-key' => sprintf(
1215 '<strong>%s</strong>. <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s.',
1216 __( 'The Secret Key is invalid', 'google-captcha' ),
1217 __( 'Check your domain configuration', 'google-captcha' ),
1218 __( 'and enter it again', 'google-captcha' )
1219 ),
1220 'incorrect-captcha-sol' => __( 'The user response is invalid', 'google-captcha' ),
1221 );
1222
1223 if ( isset( $result['reason'] ) ) {
1224 foreach ( (array)$result['reason'] as $error ) { ?>
1225 <div class="error gglcptch-test-results"><p><?php echo $error; ?></p></div>
1226 <?php }
1227 }
1228 } else { ?>
1229 <div class="updated gglcptch-test-results"><p><?php _e( 'The verification is successfully completed','google-captcha' ); ?></p></div>
1230 <?php $gglcptch_options = get_option( 'gglcptch_options' );
1231 $gglcptch_options['keys_verified'] = true;
1232 update_option( 'gglcptch_options', $gglcptch_options );
1233 }
1234 }
1235 die();
1236 }
1237 }
1238
1239 if ( ! function_exists( 'gglcptch_action_links' ) ) {
1240 function gglcptch_action_links( $links, $file ) {
1241 if ( ! is_network_admin() ) {
1242 static $this_plugin;
1243 if ( ! $this_plugin )
1244 $this_plugin = plugin_basename(__FILE__);
1245
1246 if ( $file == $this_plugin ) {
1247 $settings_link = '<a href="admin.php?page=google-captcha.php">' . __( 'Settings', 'google-captcha' ) . '</a>';
1248 array_unshift( $links, $settings_link );
1249 }
1250 }
1251 return $links;
1252 }
1253 }
1254
1255 if ( ! function_exists( 'gglcptch_shortcode_button_content' ) ) {
1256 function gglcptch_shortcode_button_content( $content ) { ?>
1257 <div id="gglcptch" style="display:none;">
1258 <input class="bws_default_shortcode" type="hidden" name="default" value="[bws_google_captcha]" />
1259 </div>
1260 <?php }
1261 }
1262
1263 if ( ! function_exists( 'gglcptch_links' ) ) {
1264 function gglcptch_links( $links, $file ) {
1265 $base = plugin_basename( __FILE__ );
1266 if ( $file == $base ) {
1267 if ( ! is_network_admin() )
1268 $links[] = '<a href="admin.php?page=google-captcha.php">' . __( 'Settings', 'google-captcha' ) . '</a>';
1269 $links[] = '<a href="http://wordpress.org/plugins/google-captcha/faq/" target="_blank">' . __( 'FAQ', 'google-captcha' ) . '</a>';
1270 $links[] = '<a href="http://support.bestwebsoft.com">' . __( 'Support', 'google-captcha' ) . '</a>';
1271 }
1272 return $links;
1273 }
1274 }
1275
1276 if ( ! function_exists ( 'gglcptch_plugin_banner' ) ) {
1277 function gglcptch_plugin_banner() {
1278 global $hook_suffix, $gglcptch_plugin_info, $gglcptch_options;
1279 if ( 'plugins.php' == $hook_suffix ) {
1280 if ( empty( $gglcptch_options ) )
1281 register_gglcptch_settings();
1282
1283 if ( empty( $gglcptch_options['public_key'] ) || empty( $gglcptch_options['private_key'] ) ) { ?>
1284 <div class="error">
1285 <p>
1286 <?php printf(
1287 '<strong>%s <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s <a target="_blank" href="%s">%s</a>.</strong>',
1288 __( 'To use Google Captcha you must get the keys from', 'google-captcha' ),
1289 __ ( 'here', 'google-captcha' ),
1290 __ ( 'and enter them on the', 'google-captcha' ),
1291 admin_url( '/admin.php?page=google-captcha.php' ),
1292 __( 'plugin setting page', 'google-captcha' )
1293 ); ?>
1294 </p>
1295 </div>
1296 <?php }
1297 if ( isset( $gglcptch_options['first_install'] ) && strtotime( '-1 week' ) > $gglcptch_options['first_install'] )
1298 bws_plugin_banner( $gglcptch_plugin_info, 'gglcptch', 'google-captcha', '676d9558f9786ab41d7de35335cf5c4d', '109', '//ps.w.org/google-captcha/assets/icon-128x128.png' );
1299
1300 bws_plugin_banner_to_settings( $gglcptch_plugin_info, 'gglcptch_options', 'google-captcha', 'admin.php?page=google-captcha.php' );
1301 }
1302
1303 if ( isset( $_GET['page'] ) && 'google-captcha.php' == $_GET['page'] ) {
1304 bws_plugin_suggest_feature_banner( $gglcptch_plugin_info, 'gglcptch_options', 'google-captcha' );
1305 }
1306 }
1307 }
1308
1309 /* add help tab */
1310 if ( ! function_exists( 'gglcptch_add_tabs' ) ) {
1311 function gglcptch_add_tabs() {
1312 $screen = get_current_screen();
1313 $args = array(
1314 'id' => 'gglcptch',
1315 'section' => '200538719'
1316 );
1317 bws_help_tab( $screen, $args );
1318 }
1319 }
1320
1321 if ( ! function_exists( 'gglcptch_delete_options' ) ) {
1322 function gglcptch_delete_options() {
1323 if ( ! function_exists( 'get_plugins' ) )
1324 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
1325 $all_plugins = get_plugins();
1326
1327 if ( ! array_key_exists( 'google-captcha-pro/google-captcha-pro.php', $all_plugins ) ) {
1328 global $wpdb;
1329 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
1330 $old_blog = $wpdb->blogid;
1331 /* Get all blog ids */
1332 $blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" );
1333 foreach ( $blogids as $blog_id ) {
1334 switch_to_blog( $blog_id );
1335 $wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}gglcptch_whitelist`;" );
1336 delete_option( 'gglcptch_options' );
1337 }
1338 switch_to_blog( $old_blog );
1339 } else {
1340 $wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}gglcptch_whitelist`;" );
1341 delete_option( 'gglcptch_options' );
1342 }
1343 }
1344
1345 require_once( dirname( __FILE__ ) . '/bws_menu/bws_include.php' );
1346 bws_include_init( plugin_basename( __FILE__ ) );
1347 bws_delete_plugin( plugin_basename( __FILE__ ) );
1348 }
1349 }
1350
1351 register_activation_hook( __FILE__, 'gglcptch_plugin_activate' );
1352
1353 add_action( 'admin_menu', 'gglcptch_admin_menu' );
1354
1355 add_action( 'init', 'gglcptch_init' );
1356 add_action( 'admin_init', 'gglcptch_admin_init' );
1357
1358 add_action( 'plugins_loaded', 'gglcptch_plugins_loaded' );
1359
1360 add_action( 'admin_enqueue_scripts', 'gglcptch_add_admin_script_styles' );
1361 add_action( 'wp_enqueue_scripts', 'gglcptch_add_styles' );
1362 add_filter( 'script_loader_tag', 'gglcptch_add_async_attribute', 10, 2 );
1363 add_action( 'admin_footer', 'gglcptch_admin_footer' );
1364 add_filter( 'pgntn_callback', 'gglcptch_pagination_callback' );
1365
1366 /* custom filter for bws button in tinyMCE */
1367 add_filter( 'bws_shortcode_button_content', 'gglcptch_shortcode_button_content' );
1368 add_shortcode( 'bws_google_captcha', 'gglcptch_display' );
1369 add_filter( 'widget_text', 'do_shortcode' );
1370
1371 add_filter( 'plugin_action_links', 'gglcptch_action_links', 10, 2 );
1372 add_filter( 'plugin_row_meta', 'gglcptch_links', 10, 2 );
1373
1374 add_action( 'admin_notices', 'gglcptch_plugin_banner' );
1375
1376 add_action( 'wp_ajax_gglcptch_captcha_check', 'gglcptch_captcha_check' );
1377 add_action( 'wp_ajax_nopriv_gglcptch_captcha_check', 'gglcptch_captcha_check' );
1378 add_action( 'wp_ajax_gglcptch-test-keys', 'gglcptch_test_keys' );
1379 add_action( 'wp_ajax_gglcptch_test_keys_verification', 'gglcptch_test_keys_verification' );