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