PluginProbe ʕ •ᴥ•ʔ
reCaptcha by BestWebSoft / 1.54
reCaptcha by BestWebSoft v1.54
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 6 years ago css 6 years ago includes 6 years ago js 6 years ago languages 6 years ago google-captcha.php 6 years ago readme.txt 6 years ago screenshot-1.png 6 years ago screenshot-2.png 6 years ago screenshot-3.png 6 years ago screenshot-4.png 6 years ago screenshot-5.png 6 years ago screenshot-6.png 6 years ago screenshot-7.png 6 years ago screenshot-8.png 6 years ago
google-captcha.php
1208 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.54
10 Author URI: https://bestwebsoft.com/
11 License: GPLv3 or later
12 */
13
14 /* © Copyright 2019 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 require_once( dirname( __FILE__ ) . '/includes/forms.php' );
31
32 /* Add menu page */
33 if ( ! function_exists( 'gglcptch_admin_menu' ) ) {
34 function gglcptch_admin_menu() {
35 global $submenu, $wp_version, $gglcptch_plugin_info;
36
37 if ( ! is_plugin_active( 'google-captcha-pro/google-captcha-pro.php' ) ) {
38 $settings_page = add_menu_page(
39 __( 'Google Captcha Settings', 'google-captcha' ),
40 'Google Captcha',
41 'manage_options',
42 'google-captcha.php',
43 'gglcptch_add_settings_page',
44 'none'
45 );
46
47 add_submenu_page(
48 'google-captcha.php',
49 __( 'Google Captcha Settings', 'google-captcha'),
50 __( 'Settings', 'google-captcha' ),
51 'manage_options',
52 'google-captcha.php',
53 'gglcptch_add_settings_page'
54 );
55
56 $whitelist_page = add_submenu_page(
57 'google-captcha.php',
58 __( 'Google Captcha Whitelist', 'google-captcha' ),
59 __( 'Whitelist', 'google-captcha' ),
60 'manage_options',
61 'google-captcha-whitelist.php',
62 'gglcptch_add_settings_page'
63 );
64
65 add_submenu_page(
66 'google-captcha.php',
67 'BWS Panel',
68 'BWS Panel',
69 'manage_options',
70 'gglcptch-bws-panel',
71 'bws_add_menu_render'
72 );
73
74 if ( isset( $submenu['google-captcha.php'] ) ) {
75 $submenu['google-captcha.php'][] = array(
76 '<span style="color:#d86463"> ' . __('Upgrade to Pro', 'google-captcha' ) . '</span>',
77 'manage_options',
78 'https://bestwebsoft.com/products/wordpress/plugins/google-captcha/?k=b850d949ccc1239cab0da315c3c822ab&pn=109&v=' . $gglcptch_plugin_info["Version"] . '&wp_v=' . $wp_version );
79 }
80
81 add_action( "load-{$settings_page}", 'gglcptch_add_tabs' );
82 add_action( "load-{$whitelist_page}", 'gglcptch_add_tabs' );
83 }
84 }
85 }
86
87 if ( ! function_exists( 'gglcptch_plugins_loaded' ) ) {
88 function gglcptch_plugins_loaded() {
89 /* Internationalization, first(!) */
90 load_plugin_textdomain( 'google-captcha', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
91 }
92 }
93
94 if ( ! function_exists( 'gglcptch_init' ) ) {
95 function gglcptch_init() {
96 global $gglcptch_plugin_info, $gglcptch_options;
97
98 require_once( dirname( __FILE__ ) . '/bws_menu/bws_include.php' );
99 bws_include_init( plugin_basename( __FILE__ ) );
100
101 if ( empty( $gglcptch_plugin_info ) ) {
102 if ( ! function_exists( 'get_plugin_data' ) ) {
103 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
104 }
105 $gglcptch_plugin_info = get_plugin_data( __FILE__ );
106 }
107
108 /* Function check if plugin is compatible with current WP version */
109 bws_wp_min_version_check( plugin_basename( __FILE__ ), $gglcptch_plugin_info, '4.0' );
110
111 $is_admin = is_admin() && ! defined( 'DOING_AJAX' );
112 /* Call register settings function */
113 if ( ! $is_admin || ( isset( $_GET['page'] ) && 'google-captcha.php' == $_GET['page'] ) ) {
114 register_gglcptch_settings();
115 }
116
117 /* Add hooks */
118 if ( ! $is_admin && ! empty( $gglcptch_options['public_key'] ) && ! empty( $gglcptch_options['private_key'] ) ) {
119 gglcptch_add_actions();
120 }
121 }
122 }
123
124 /**
125 * Activation plugin function
126 */
127 if ( ! function_exists( 'gglcptch_plugin_activate' ) ) {
128 function gglcptch_plugin_activate( $networkwide ) {
129 /* Activation function for network, check if it is a network activation - if so, run the activation function for each blog id */
130 if ( is_multisite() ) {
131 switch_to_blog( 1 );
132 register_uninstall_hook( __FILE__, 'gglcptch_delete_options' );
133 restore_current_blog();
134 } else {
135 register_uninstall_hook( __FILE__, 'gglcptch_delete_options' );
136 }
137 }
138 }
139
140 if ( ! function_exists( 'gglcptch_admin_init' ) ) {
141 function gglcptch_admin_init() {
142 global $bws_plugin_info, $gglcptch_plugin_info;
143
144 if ( empty( $bws_plugin_info ) ) {
145 $bws_plugin_info = array( 'id' => '109', 'version' => $gglcptch_plugin_info["Version"] );
146 }
147
148 }
149 }
150
151 /* Add google captcha styles */
152 if ( ! function_exists( 'gglcptch_add_admin_script_styles' ) ) {
153 function gglcptch_add_admin_script_styles() {
154 global $gglcptch_plugin_info, $gglcptch_options;
155
156 /* css for displaing an icon */
157 wp_enqueue_style( 'gglcptch_admin_page_stylesheet', plugins_url( 'css/admin_page.css', __FILE__ ) );
158
159 if ( $gglcptch_options['hide_badge'] ) {
160 wp_enqueue_style( 'gglcptch_hide', plugins_url( 'css/hide_badge.css', __FILE__ ), array(), $gglcptch_plugin_info['Version'] );
161 }
162 if ( isset( $_REQUEST['page'] ) && ( 'google-captcha.php' == $_REQUEST['page'] || 'google-captcha-whitelist.php' == $_REQUEST['page'] ) ) {
163 wp_enqueue_style( 'gglcptch_stylesheet', plugins_url( 'css/style.css', __FILE__ ), array(), $gglcptch_plugin_info['Version'] );
164 wp_enqueue_script( 'gglcptch_admin_script', plugins_url( 'js/admin_script.js', __FILE__ ), array( 'jquery', 'jquery-ui-accordion' ), $gglcptch_plugin_info['Version'] );
165
166 bws_enqueue_settings_scripts();
167 bws_plugins_include_codemirror();
168 }
169 }
170 }
171
172 /* Add google captcha admin styles for test key */
173 if ( ! function_exists( 'gglcptch_admin_footer' ) ) {
174 function gglcptch_admin_footer() {
175 global $gglcptch_plugin_info, $gglcptch_options;
176 if ( isset( $_REQUEST['page'] ) && 'google-captcha.php' == $_REQUEST['page'] ) {
177
178 /* update $gglcptch_options */
179 register_gglcptch_settings();
180
181 $api_url = gglcptch_get_api_url();
182
183 /* for gglcptch test key */
184 if ( isset( $gglcptch_options['recaptcha_version'] ) && in_array( $gglcptch_options['recaptcha_version'], array( 'v2', 'invisible' ) ) ) {
185 $deps = ( ! empty( $gglcptch_options['disable_submit'] ) ) ? array( 'gglcptch_pre_api' ) : array( 'jquery' );
186 } else {
187 $deps = array();
188 }
189 wp_register_script( 'gglcptch_api', $api_url,$deps, $gglcptch_plugin_info['Version'], true );
190 gglcptch_add_scripts();
191 }
192 }
193 }
194
195 /**
196 * Remove dublicate scripts
197 */
198 if ( ! function_exists( 'gglcptch_remove_dublicate_scripts' ) ) {
199 function gglcptch_remove_dublicate_scripts() {
200 global $wp_scripts;
201
202 if ( ! is_object( $wp_scripts ) || empty( $wp_scripts ) ) {
203 return false;
204 }
205
206 foreach ( $wp_scripts->registered as $script_name => $args ) {
207 if ( preg_match( "|google\.com/recaptcha/api\.js|", $args->src ) && 'gglcptch_api' != $script_name ) {
208 /* remove a previously enqueued script */
209 wp_dequeue_script( $script_name );
210 }
211 }
212 }
213 }
214
215 /**
216 * Add google captcha styles
217 */
218 if ( ! function_exists( 'gglcptch_add_styles' ) ) {
219 function gglcptch_add_styles() {
220 global $gglcptch_plugin_info, $gglcptch_options;
221 wp_enqueue_style( 'gglcptch', plugins_url( 'css/gglcptch.css', __FILE__ ), array(), $gglcptch_plugin_info["Version"] );
222
223 if ( defined( 'BWS_ENQUEUE_ALL_SCRIPTS' ) && BWS_ENQUEUE_ALL_SCRIPTS ) {
224 if ( ! wp_script_is( 'gglcptch_api', 'registered' ) ) {
225 $api_url = gglcptch_get_api_url();
226 if ( isset( $gglcptch_options['recaptcha_version'] ) && in_array( $gglcptch_options['recaptcha_version'], array( 'v2', 'invisible' ) ) ) {
227 $deps = ( ! empty( $gglcptch_options['disable_submit'] ) ) ? array( 'gglcptch_pre_api' ) : array( 'jquery' );
228 } else {
229 $deps = array();
230 }
231
232 wp_register_script( 'gglcptch_api', $api_url,$deps, $gglcptch_plugin_info['Version'], true );
233
234 add_action( 'wp_footer', 'gglcptch_add_scripts' );
235 if (
236 $gglcptch_options['login_form'] ||
237 $gglcptch_options['reset_pwd_form'] ||
238 $gglcptch_options['registration_form']
239 ) {
240 add_action('login_footer', 'gglcptch_add_scripts');
241 }
242 }
243 }
244 }
245 }
246
247 /**
248 * Add google captcha js scripts
249 */
250 if ( ! function_exists( 'gglcptch_add_scripts' ) ) {
251 function gglcptch_add_scripts() {
252 global $gglcptch_options, $gglcptch_plugin_info;
253
254 if ( empty( $gglcptch_options ) ) {
255 register_gglcptch_settings();
256 }
257
258 if ( isset( $gglcptch_options['recaptcha_version'] ) ) {
259 gglcptch_remove_dublicate_scripts();
260 if ( ! empty( $gglcptch_options['disable_submit'] ) ) {
261 wp_enqueue_script( 'gglcptch_pre_api', plugins_url( 'js/pre-api-script.js', __FILE__ ), array( 'jquery'), $gglcptch_plugin_info['Version'], true );
262 wp_localize_script( 'gglcptch_pre_api', 'gglcptch_pre', array(
263 'messages' => array(
264 'in_progress' => __( 'Please wait until Google reCAPTCHA is loaded.', 'google-captcha' ),
265 'timeout' => __( 'Failed to load Google reCAPTCHA. Please check your internet connection and reload this page.', 'google-captcha' )
266 ),
267 'custom_callback' => apply_filters( 'gglcptch_custom_callback', '' )
268 ) );
269 }
270 }
271
272 wp_enqueue_script( 'gglcptch_script', plugins_url( 'js/script.js', __FILE__ ), array( 'jquery', 'gglcptch_api' ), $gglcptch_plugin_info["Version"], true );
273
274 $version = $gglcptch_options['recaptcha_version'] == 'v2' ? '_v2' : '';
275
276 wp_localize_script( 'gglcptch_script', 'gglcptch', array(
277 'options' => array(
278 'version' => $gglcptch_options['recaptcha_version'],
279 'sitekey' => $gglcptch_options['public_key'],
280 'theme' => $gglcptch_options[ 'theme' . $version ],
281 'error' => sprintf( '<strong>%s</strong>:&nbsp;%s', __( 'Warning', 'google-captcha' ), gglcptch_get_message( 'multiple_blocks' ) ),
282 'disable' => $gglcptch_options['disable_submit_button']
283 ),
284 'vars' => array(
285 'visibility' => ( 'login_footer' == current_filter() )
286 )
287 ) );
288
289 if ( $gglcptch_options['hide_badge'] ) {
290 wp_enqueue_style( 'gglcptch_hide', plugins_url( 'css/hide_badge.css', __FILE__ ), array(), $gglcptch_plugin_info['Version'] );
291 }
292 }
293 }
294
295 if ( ! function_exists( 'gglcptch_pagination_callback' ) ) {
296 function gglcptch_pagination_callback( $content ) {
297 $content .= "if ( typeof Recaptcha != 'undefined' || typeof grecaptcha != 'undefined' ) { gglcptch.prepare(); }";
298 return $content;
299 }
300 }
301
302 /**
303 * Add the "async" attribute to our registered script.
304 */
305 if ( ! function_exists( 'gglcptch_add_async_attribute' ) ) {
306 function gglcptch_add_async_attribute( $tag, $handle ) {
307 if ( 'gglcptch_api' == $handle ) {
308 $tag = str_replace( ' src', ' data-cfasync="false" async="async" defer="defer" src', $tag );
309 }
310 return $tag;
311 }
312 }
313
314 if ( ! function_exists( 'gglcptch_create_table' ) ) {
315 function gglcptch_create_table() {
316 global $wpdb;
317 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
318
319 $sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}gglcptch_whitelist` (
320 `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
321 `ip` CHAR(31) NOT NULL,
322 `ip_from_int` BIGINT,
323 `ip_to_int` BIGINT,
324 `add_time` DATETIME,
325 PRIMARY KEY (`id`)
326 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
327 dbDelta( $sql );
328
329 /* add unique key */
330 if ( ! $wpdb->query( "SHOW KEYS FROM `{$wpdb->prefix}gglcptch_whitelist` WHERE Key_name='ip'" ) ) {
331 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}gglcptch_whitelist` ADD UNIQUE(`ip`);" );
332 }
333 }
334 }
335
336 /* Google catpcha settings */
337 if ( ! function_exists( 'register_gglcptch_settings' ) ) {
338 function register_gglcptch_settings() {
339 global $gglcptch_options, $gglcptch_plugin_info;
340
341 $plugin_db_version = '0.1';
342
343 /* Install the option defaults */
344 if ( ! get_option( 'gglcptch_options' ) ) {
345 add_option( 'gglcptch_options', gglcptch_get_default_options() );
346 }
347 /* Get options from the database */
348 $gglcptch_options = get_option( 'gglcptch_options' );
349
350 /* Array merge incase this version has added new options */
351 if (
352 ! isset( $gglcptch_options['plugin_option_version'] ) ||
353 $gglcptch_options['plugin_option_version'] != $gglcptch_plugin_info["Version"]
354 ) {
355 $gglcptch_options = array_merge( gglcptch_get_default_options(), $gglcptch_options );
356 $gglcptch_options['plugin_option_version'] = $gglcptch_plugin_info["Version"];
357
358 if ( is_multisite() ) {
359 switch_to_blog( 1 );
360 register_uninstall_hook( __FILE__, 'gglcptch_delete_options' );
361 restore_current_blog();
362 } else {
363 register_uninstall_hook( __FILE__, 'gglcptch_delete_options' );
364 }
365 update_option( 'gglcptch_options', $gglcptch_options );
366 }
367 /* Update tables when update plugin and tables changes*/
368 if (
369 ! isset( $gglcptch_options['plugin_db_version'] ) ||
370 (
371 isset( $gglcptch_options['plugin_db_version'] ) &&
372 $gglcptch_options['plugin_db_version'] != $plugin_db_version
373 )
374 ) {
375 if ( ! isset( $gglcptch_options['plugin_db_version'] ) ) {
376 gglcptch_create_table();
377 }
378 $gglcptch_options['plugin_db_version'] = $plugin_db_version;
379 update_option( 'gglcptch_options', $gglcptch_options );
380 }
381 }
382 }
383
384 if ( ! function_exists( 'gglcptch_get_default_options' ) ) {
385 function gglcptch_get_default_options() {
386 global $gglcptch_plugin_info;
387
388 $default_options = array(
389 'whitelist_message' => __( 'You are in the whitelist', 'google-captcha' ),
390 'public_key' => '',
391 'private_key' => '',
392 'login_form' => 0,
393 'registration_form' => 0,
394 'reset_pwd_form' => 1,
395 'comments_form' => 0,
396 'contact_form' => 0,
397 'testimonials' => 0,
398 'theme' => 'red',
399 'theme_v2' => 'light',
400 'recaptcha_version' => 'v2',
401 'plugin_option_version' => $gglcptch_plugin_info["Version"],
402 'first_install' => strtotime( "now" ),
403 'display_settings_notice' => 1,
404 'suggest_feature_banner' => 1,
405 'score_v3' => 0.5,
406 'hide_badge' => 0,
407 'disable_submit_button' => 0
408 );
409
410 if ( function_exists( 'get_editable_roles' ) ) {
411 foreach ( get_editable_roles() as $role => $fields ) {
412 $default_options[ $role ] = '0';
413 }
414 }
415 return $default_options;
416 }
417 }
418
419 if ( ! function_exists( 'gglcptch_plugin_status' ) ) {
420 function gglcptch_plugin_status( $plugins, $all_plugins, $is_network ) {
421 $result = array(
422 'status' => '',
423 'plugin' => '',
424 'plugin_info' => array(),
425 );
426 foreach ( ( array )$plugins as $plugin ) {
427 if ( array_key_exists( $plugin, $all_plugins ) ) {
428 if (
429 ( $is_network && is_plugin_active_for_network( $plugin ) ) ||
430 ( ! $is_network && is_plugin_active( $plugin ) )
431 ) {
432 $result['status'] = 'activated';
433 $result['plugin'] = $plugin;
434 $result['plugin_info'] = $all_plugins[ $plugin ];
435 break;
436 } else {
437 $result['status'] = 'deactivated';
438 $result['plugin'] = $plugin;
439 $result['plugin_info'] = $all_plugins[ $plugin ];
440 }
441
442 }
443 }
444 if ( empty( $result['status'] ) ) {
445 $result['status'] = 'not_installed';
446 }
447 return $result;
448 }
449 }
450
451 if ( ! function_exists( 'gglcptch_whitelisted_ip' ) ) {
452 function gglcptch_whitelisted_ip() {
453 global $wpdb, $gglcptch_options;
454 $checked = false;
455 if ( empty( $gglcptch_options ) ) {
456 $gglcptch_options = get_option( 'gglcptch_options' );
457 }
458 $whitelist_exist = $wpdb->query( "SHOW TABLES LIKE '{$wpdb->prefix}gglcptch_whitelist'" );
459 if ( 1 === $whitelist_exist ) {
460 $ip = gglcptch_get_ip();
461
462 if ( ! empty( $ip ) ) {
463 $ip_int = sprintf( '%u', ip2long( $ip ) );
464 $result = $wpdb->get_var(
465 "SELECT `id`
466 FROM `{$wpdb->prefix}gglcptch_whitelist`
467 WHERE ( `ip_from_int` <= {$ip_int} AND `ip_to_int` >= {$ip_int} ) OR `ip` LIKE '{$ip}' LIMIT 1;"
468 );
469 $checked = is_null( $result ) || ! $result ? false : true;
470 }
471 }
472 return $checked;
473 }
474 }
475
476 /* Display settings page */
477 if ( ! function_exists( 'gglcptch_add_settings_page' ) ) {
478 function gglcptch_add_settings_page() {
479 global $gglcptch_plugin_info;
480 require_once( dirname( __FILE__ ) . '/includes/pro_banners.php' ); ?>
481 <div class="wrap">
482 <?php if ( 'google-captcha.php' == $_GET['page'] ) {
483 require_once( dirname( __FILE__ ) . '/includes/class-gglcptch-settings-tabs.php' );
484 $page = new Gglcptch_Settings_Tabs( plugin_basename( __FILE__ ) ); ?>
485 <h1><?php _e( 'Google Captcha Settings', 'google-captcha' ); ?></h1>
486 <noscript><div class="error below-h2"><p><strong><?php _e( "Please enable JavaScript in your browser.", 'google-captcha' ); ?></strong></p></div></noscript>
487 <?php $page->display_content();
488 } else {
489 require_once( dirname( __FILE__ ) . '/includes/whitelist.php' );
490 $page = new Gglcptch_Whitelist( plugin_basename( __FILE__ ) );
491 if ( is_object( $page ) ) {
492 $page->display_content();
493 }
494
495 bws_plugin_reviews_block( $gglcptch_plugin_info['Name'], 'google-captcha' );
496 } ?>
497 </div>
498 <?php }
499 }
500
501 if ( ! function_exists( 'gglcptch_is_recaptcha_required' ) ) {
502 function gglcptch_is_recaptcha_required( $form_slug = '', $is_user_logged_in = null ) {
503 global $gglcptch_options;
504
505 if ( is_null( $is_user_logged_in ) ) {
506 $is_user_logged_in = is_user_logged_in();
507 }
508
509 if ( empty( $gglcptch_options ) ) {
510 $gglcptch_options = get_option( 'gglcptch_options' );
511 if ( empty( $gglcptch_options ) ) {
512 register_gglcptch_settings();
513 }
514 }
515
516 $result =
517 ! isset( $gglcptch_options[ $form_slug ] ) ||
518 (
519 ! empty( $gglcptch_options[ $form_slug ] ) &&
520 ( ! $is_user_logged_in || ! gglcptch_is_hidden_for_role() )
521 );
522
523 return $result;
524 }
525 }
526
527 /* Checking current user role */
528 if ( ! function_exists( 'gglcptch_is_hidden_for_role' ) ) {
529 function gglcptch_is_hidden_for_role() {
530 global $current_user, $gglcptch_options;
531
532 if ( ! is_user_logged_in() ) {
533 return false;
534 }
535
536 if ( ! empty( $current_user->roles[0] ) ) {
537 $role = $current_user->roles[0];
538 if ( empty( $gglcptch_options ) ) {
539 register_gglcptch_settings();
540 }
541 return ! empty( $gglcptch_options[ $role ] );
542 } else {
543 return false;
544 }
545 }
546 }
547
548 /* Display google captcha via shortcode */
549 if ( ! function_exists( 'gglcptch_display' ) ) {
550 function gglcptch_display( $content = false ) {
551 global $gglcptch_options, $gglcptch_count, $gglcptch_plugin_info;
552
553 if ( empty( $gglcptch_options ) ) {
554 register_gglcptch_settings();
555 }
556
557 if ( ! gglcptch_whitelisted_ip() || ( isset( $_GET['action'] ) && 'gglcptch-test-keys' == $_GET['action'] ) ) {
558
559 if ( ! $gglcptch_count ) {
560 $gglcptch_count = 1;
561 }
562
563 $content .= '<div class="gglcptch gglcptch_' . $gglcptch_options['recaptcha_version'] . '">';
564
565 if ( $gglcptch_options['hide_badge'] && 'v2' != $gglcptch_options['recaptcha_version'] ) {
566 $content .= sprintf(
567 '<div class="google-captcha-notice">%s<a href="https://policies.google.com/privacy" target="_blank">%s</a>%s<a href="https://policies.google.com/terms" target="_blank">%s</a>%s</div>',
568 __( 'This site is protected by reCAPTCHA and the Google ', 'google-captcha' ),
569 __( 'Privacy Policy', 'google-captcha' ),
570 __( ' and ', 'google-captcha' ),
571 __( 'Terms of Service', 'google-captcha' ),
572 __( ' apply.', 'google-captcha' )
573 );
574 }
575 if ( ! $gglcptch_options['private_key'] || ! $gglcptch_options['public_key'] ) {
576 if ( current_user_can( 'manage_options' ) ) {
577 $content .= sprintf(
578 '<strong>%s <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s <a target="_blank" href="%s">%s</a>.</strong>',
579 __( 'To use Google Captcha you must get the keys from', 'google-captcha' ),
580 __( 'here', 'google-captcha' ),
581 __( 'and enter them on the', 'google-captcha' ),
582 admin_url( '/admin.php?page=google-captcha.php' ),
583 __( 'plugin setting page', 'google-captcha' )
584 );
585 }
586 $content .= '</div>';
587 $gglcptch_count++;
588 return $content;
589 }
590
591 $api_url = gglcptch_get_api_url();
592
593 /* generating random id value in case of getting content with pagination plugin for not getting duplicate id values */
594 $id = mt_rand();
595 if ( isset( $gglcptch_options['recaptcha_version'] ) && in_array( $gglcptch_options['recaptcha_version'], array( 'v2', 'invisible' ) ) ) {
596 $content .= '<div id="gglcptch_recaptcha_' . $id . '" class="gglcptch_recaptcha"></div>
597 <noscript>
598 <div style="width: 302px;">
599 <div style="width: 302px; height: 422px; position: relative;">
600 <div style="width: 302px; height: 422px; position: absolute;">
601 <iframe src="https://www.google.com/recaptcha/api/fallback?k=' . $gglcptch_options['public_key'] . '" frameborder="0" scrolling="no" style="width: 302px; height:422px; border-style: none;"></iframe>
602 </div>
603 </div>
604 <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;">
605 <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>
606 </div>
607 </div>
608 </noscript>';
609 $deps = ( ! empty( $gglcptch_options['disable_submit'] ) ) ? array( 'gglcptch_pre_api' ) : array( 'jquery' );
610 } elseif ( isset( $gglcptch_options['recaptcha_version'] ) && 'v3' == $gglcptch_options['recaptcha_version'] ) {
611 $content .= '<input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response"> ' ;
612 $content .= '<script src="' . $api_url . '"></script>
613 <script>
614 grecaptcha.ready(function() {
615 grecaptcha.execute(\''. $gglcptch_options['public_key'] .'\', {action: \'BWS_reCaptcha\'}).then(function(token) {
616 document.querySelectorAll( "#g-recaptcha-response" ).forEach( elem => ( elem.value = token ) );
617 });
618 });
619 </script>';
620 }
621 $content .= '</div>';
622 $gglcptch_count++;
623
624 /* register reCAPTCHA script */
625 if ( ! wp_script_is( 'gglcptch_api', 'registered' ) ) {
626 if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v3' == $gglcptch_options['recaptcha_version'] ) {
627 wp_register_script( 'gglcptch_api', $api_url,false, null, false );
628 } else {
629 wp_register_script( 'gglcptch_api', $api_url, $deps, $gglcptch_plugin_info['Version'], true );
630 }
631 add_action( 'wp_footer', 'gglcptch_add_scripts' );
632 if (
633 $gglcptch_options['login_form'] ||
634 $gglcptch_options['reset_pwd_form'] ||
635 $gglcptch_options['registration_form']
636 ) {
637 add_action( 'login_footer', 'gglcptch_add_scripts' );
638 }
639 }
640 if (
641 ( ! isset( $_SERVER['REQUEST_URI'] ) ) ||
642 ( ! strstr( $_SERVER['REQUEST_URI'], '/wp-login.php' ) ) ||
643 ( '/wp-login.php?action=register' == $_SERVER['REQUEST_URI'] && $gglcptch_options['registration_form'] ) ||
644 ( '/wp-login.php?action=lostpassword' == $_SERVER['REQUEST_URI'] && $gglcptch_options['reset_pwd_form'] ) ||
645 ( '/wp-login.php' == $_SERVER['REQUEST_URI'] && $gglcptch_options['login_form'] ) ||
646 ( strstr( $_SERVER['REQUEST_URI'], '/wp-login.php' ) && strstr( $_SERVER['REQUEST_URI'], 'loggedout' ) && $gglcptch_options['login_form'] )
647 ) {
648 gglcptch_add_styles();
649 }
650 } elseif ( ! empty( $gglcptch_options['whitelist_message'] ) ) {
651 $content .= '<label class="gglcptch_whitelist_message" style="display: block;">' . $gglcptch_options['whitelist_message'] . '</label>';
652 }
653
654 return $content;
655 }
656 }
657
658 /* Return google captcha content for custom form */
659 if ( ! function_exists( 'gglcptch_display_custom' ) ) {
660 function gglcptch_display_custom( $content = '', $form_slug = '' ) {
661 if ( gglcptch_is_recaptcha_required( $form_slug ) ) {
662 $content = gglcptch_display( $content );
663 }
664
665 return $content;
666 }
667 }
668
669 /* Get the reCAPTCHA api js url that corresponds to the reCAPTCHA version. */
670 if ( ! function_exists( 'gglcptch_get_api_url' ) ) {
671 function gglcptch_get_api_url() {
672 global $gglcptch_options;
673
674 switch ( true ) {
675 case (
676 isset( $gglcptch_options['recaptcha_version'] ) &&
677 in_array( $gglcptch_options['recaptcha_version'], array( 'v2', 'invisible' ) )
678 ) :
679 $callback = ( ! empty( $gglcptch_options['disable_submit'] ) ) ? 'onload=gglcptch_onload_callback&' : '';
680 $api_url = sprintf( 'https://www.google.com/recaptcha/api.js?%srender=explicit', $callback );
681 break;
682 case (
683 isset( $gglcptch_options['recaptcha_version'] ) &&
684 'v3' == $gglcptch_options['recaptcha_version']
685 ) :
686 $api_url = sprintf( 'https://www.google.com/recaptcha/api.js?render=%s', $gglcptch_options['public_key'] );
687 break;
688 default :
689 $api_url = 'https://www.google.com/recaptcha/api/js/recaptcha_ajax.js';
690 }
691 return $api_url;
692 }
693 }
694
695 if ( ! function_exists( 'gglcptch_get_response' ) ) {
696 function gglcptch_get_response( $privatekey, $remote_ip ) {
697 $args = array(
698 'body' => array(
699 'secret' => $privatekey,
700 'response' => stripslashes( esc_html( $_POST["g-recaptcha-response"] ) ),
701 'remoteip' => $remote_ip,
702 ),
703 'sslverify' => false
704 );
705 $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $args );
706 return json_decode( wp_remote_retrieve_body( $resp ), true );
707 }
708 }
709
710 /* Check google captcha */
711 if ( ! function_exists( 'gglcptch_check' ) ) {
712 function gglcptch_check( $form = 'general', $debug = false ) {
713 global $gglcptch_options;
714
715 if ( gglcptch_whitelisted_ip() && 'gglcptch_test' != $form ) {
716 $result = array(
717 'response' => true,
718 'reason' => ''
719 );
720 return $result;
721 }
722
723 if ( empty( $gglcptch_options ) ) {
724 register_gglcptch_settings();
725 }
726
727 if ( ! $gglcptch_options['public_key'] || ! $gglcptch_options['private_key'] ) {
728 $errors = new WP_Error;
729 $errors->add( 'gglcptch_error', gglcptch_get_message() );
730 return array(
731 'response' => false,
732 'reason' => 'ERROR_NO_KEYS',
733 'errors' => $errors
734 );
735 }
736
737 $gglcptch_remote_addr = filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP );
738
739 if (
740 isset( $gglcptch_options['recaptcha_version'] ) &&
741 in_array( $gglcptch_options['recaptcha_version'], array( 'v2', 'invisible', 'v3' ) )
742 ) {
743 if ( ! isset( $_POST["g-recaptcha-response"] ) ) {
744 $result = array(
745 'response' => false,
746 'reason' => 'RECAPTCHA_NO_RESPONSE'
747 );
748 } elseif ( empty( $_POST["g-recaptcha-response"] ) ) {
749 $result = array(
750 'response' => false,
751 'reason' => 'RECAPTCHA_EMPTY_RESPONSE'
752 );
753 } else {
754 $response = gglcptch_get_response( $gglcptch_options['private_key'], $gglcptch_remote_addr );
755 if ( isset( $response['success'] ) && !! $response['success'] ) {
756 if ( 'v3' == $gglcptch_options['recaptcha_version'] && $response['score'] < $gglcptch_options['score_v3'] ) {
757 $result = array(
758 'response' => false,
759 'reason' => 'RECAPTCHA_SMALL_SCORE'
760 );
761 } else {
762 $result = array(
763 'response' => true,
764 'reason' => ''
765 );
766 }
767 } else {
768 if (
769 ! $debug &&
770 (
771 in_array( 'missing-input-secret', $response['error-codes'] ) ||
772 in_array( 'invalid-input-secret', $response['error-codes'] )
773 )
774 ) {
775 $result = array(
776 'response' => false,
777 'reason' => 'ERROR_WRONG_SECRET'
778 );
779 } else {
780 $result = array(
781 'response' => false,
782 'reason' => $debug ? $response['error-codes'] : 'VERIFICATION_FAILED'
783 );
784 }
785 }
786 }
787 }
788
789 if ( ! $result['response'] ) {
790 $result['errors'] = new WP_Error;
791 if ( ! $debug && ! in_array( $result['reason'], array( 'ERROR_WRONG_SECRET', 'ERROR_NO_KEYS' ) ) ) {
792 $result['errors']->add( 'gglcptch_error', gglcptch_get_message( $result['reason'] ) );
793 }
794 }
795 $result = apply_filters( 'gglcptch_limit_attempts_check', $result, $form );
796 return $result;
797 }
798 }
799
800 /**
801 * Check google captcha for custom form
802 * @since 1.32
803 * @param bool $allow (Optional) initial value wheter the previous verification is passed
804 * @param string $return_format (Optional) The type of variable to be returned when recaptcha is failed.
805 * @param string $form_slug (Optional) The slug of the form to check.
806 * Default is empty string. When specified, the reCAPTCHA check may be skipped if the form is disabled on the plugin settings page.
807 * @return mixed $allow True if ReCapthca is successfully completed, error message string, WP_Error object or false otherwise, depending on the $return_format value.
808 */
809 if ( ! function_exists( 'gglcptch_check_custom' ) ) {
810 function gglcptch_check_custom( $allow = true, $return_format = 'bool', $form_slug = '' ) {
811
812 if ( true !== $allow ) {
813 return $allow;
814 }
815
816 if ( gglcptch_is_recaptcha_required( $form_slug ) ) {
817 $gglcptch_check = gglcptch_check();
818
819 if ( ! $gglcptch_check['response'] && 'ERROR_NO_KEYS' == $gglcptch_check['reason'] ) {
820 return $allow;
821 }
822
823 $la_result = ( ! empty( $form_slug ) ) ? gglcptch_handle_by_limit_attempts( $gglcptch_check['response'], $form_slug ) : true;
824
825 if ( ! $gglcptch_check['response'] || true !== $la_result ) {
826 if ( ! in_array( $return_format, array( 'bool', 'string', 'wp_error' ) ) ) {
827 $return_format = 'bool';
828 }
829
830 switch ( $return_format ) {
831 case 'string':
832 $allow = '';
833 if ( true !== $la_result ) {
834 if ( is_wp_error( $la_result ) ) {
835 $allow .= $la_result->get_error_message();
836 } elseif ( is_string( $la_result ) ) {
837 $allow .= $la_result;
838 }
839 }
840 if ( ! $gglcptch_check['response'] ) {
841 $allow .= ( ( '' != $allow ) ? "&nbsp;" : '' ) . gglcptch_get_message();
842 }
843 break;
844 case 'wp_error':
845 $allow = new WP_Error();
846 if ( true !== $la_result ) {
847 if ( is_wp_error( $la_result ) ) {
848 $allow = $la_result;
849 } elseif ( is_string( $la_result ) ) {
850 $allow->add( 'gglcptch_la_error', $la_result );
851 }
852 }
853 if ( ! $gglcptch_check['response'] ) {
854 $error_message = sprintf( '<strong>%s</strong>:&nbsp;%s', __( 'Error', 'google-captcha' ), gglcptch_get_message() );
855 $allow->add( 'gglcptch_error', $error_message );
856 }
857 break;
858 case 'bool':
859 default:
860 $allow = false;
861 break;
862 }
863 }
864 }
865
866 return $allow;
867 }
868 }
869
870 /* Limit Attempts plugin check */
871 if ( ! function_exists( 'gglcptch_limit_attempts_check' ) ) {
872 function gglcptch_limit_attempts_check( $gglcptch_check, $form ){
873
874 $result = gglcptch_handle_by_limit_attempts( $gglcptch_check['response'], $form );
875
876 if ( true !== $result ) {
877 $gglcptch_check['response'] = false;
878 if ( 'login_form' != $form ) {
879 if ( is_wp_error( $result ) ) {
880 $gglcptch_check['errors']->add( 'lmttmpts_error', $result->get_error_message() );
881 } elseif ( is_string( $result ) ) {
882 $gglcptch_check['errors']->add( 'lmttmpts_error', $result );
883 }
884 }
885 return $gglcptch_check;
886 } else {
887 if ( 'contact_form' == $form ) {
888 $gglcptch_check['response'] = true;
889 }
890 return $gglcptch_check;
891 }
892 }
893 }
894
895 /**
896 *
897 * @since 1.32
898 */
899 if ( ! function_exists( 'gglcptch_handle_by_limit_attempts' ) ) {
900 function gglcptch_handle_by_limit_attempts( $check_result, $form_slug = 'login_form' ) {
901 global $gglcptch_forms;
902
903 if ( ! has_filter( 'lmtttmpts_check_ip' ) ) {
904 return $check_result;
905 }
906
907 if ( empty( $gglcptch_forms ) ) {
908 $gglcptch_forms = gglcptch_get_forms();
909 }
910
911 $la_form_slug = "{$form_slug}_recaptcha_check";
912
913 /* if reCAPTCHA answer is right */
914 if ( true == $check_result ) {
915 /* check if user IP is blocked in the Limit Attempts plugin lists */
916 $check_result = apply_filters( 'lmtttmpts_check_ip', $check_result );
917 do_action( 'lmtttmpts_form_success', $la_form_slug, gglcptch_get_ip(), array( 'form_name' => $gglcptch_forms[ $form_slug ]['form_name'] ) );
918 } else {
919 /* if reCAPTCHA answer is wrong */
920 $form_data = array( 'form_name' => $gglcptch_forms[ $form_slug ]['form_name'] );
921
922 $la_error = apply_filters( 'lmtttmpts_form_fail', $la_form_slug, '', $form_data );
923 if ( ! empty( $la_error ) && $la_form_slug != $la_error ) {
924 if ( is_wp_error( $check_result ) ) {
925 $check_result->add( "gglcptch_error_lmttmpts", $la_error );
926 } elseif ( is_string( $check_result ) ) {
927 $check_result .= '<br />' . $la_error;
928 } else {
929 $check_result = $la_error;
930 }
931 }
932 }
933
934 return $check_result;
935 }
936 }
937
938 if ( ! function_exists( 'gglcptch_get_ip' ) ) {
939 function gglcptch_get_ip() {
940 $ip = '';
941 if ( isset( $_SERVER ) ) {
942 $server_vars = array( 'HTTP_X_REAL_IP', 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'REMOTE_ADDR' );
943 foreach( $server_vars as $var ) {
944 if ( ! empty( $_SERVER[ $var ] ) ) {
945 if ( filter_var( $_SERVER[ $var ], FILTER_VALIDATE_IP ) ) {
946 $ip = $_SERVER[ $var ];
947 break;
948 } else { /* if proxy */
949 $ip_array = explode( ',', $_SERVER[ $var ] );
950 if ( is_array( $ip_array ) && ! empty( $ip_array ) && filter_var( $ip_array[0], FILTER_VALIDATE_IP ) ) {
951 $ip = $ip_array[0];
952 break;
953 }
954 }
955 }
956 }
957 }
958 return $ip;
959 }
960 }
961
962 /**
963 * Retrieve the message that corresponds to its message code
964 * @since 1.29
965 * @param string $message_code used to switch the corresponding message
966 * @param boolean $echo 'false' is default. If 'false' - returns a message, if 'true' - first, echo a message and then return it.
967 * @return string $message Returned message.
968 */
969 if ( ! function_exists( 'gglcptch_get_message' ) ) {
970 function gglcptch_get_message( $message_code = 'incorrect', $echo = false ) {
971
972 $message = '';
973
974 $messages = array(
975 /* custom error */
976 'RECAPTCHA_EMPTY_RESPONSE' => __( 'User response is missing.', 'google-captcha' ),
977 /* v2 error */
978 'missing-input-secret' => __( 'Secret Key is missing.', 'google-captcha' ),
979 'invalid-input-secret' => sprintf(
980 '<strong>%s</strong> <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s.',
981 __( 'Secret Key is invalid.', 'google-captcha' ),
982 __( 'Check your domain configurations', 'google-captcha' ),
983 __( 'and enter it again', 'google-captcha' )
984 ),
985 'incorrect-captcha-sol' => __( 'User response is invalid', 'google-captcha' ),
986 'incorrect' => __( 'You have entered an incorrect reCAPTCHA value.', 'google-captcha' ),
987 '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' ),
988 /* v3 error */
989 'RECAPTCHA_SMALL_SCORE' => __( 'reCAPTCHA v3 test failed', 'google-captcha' )
990 );
991
992 if ( isset( $messages[ $message_code ] ) ) {
993 $message = $messages[ $message_code ];
994 } else {
995 $message = $messages['incorrect'];
996 }
997
998 if ( $echo ) {
999 echo $message;
1000 }
1001
1002 return $message;
1003 }
1004 }
1005
1006 if ( ! function_exists( 'gglcptch_is_woocommerce_page' ) ) {
1007 function gglcptch_is_woocommerce_page() {
1008 $traces = debug_backtrace();
1009
1010 foreach( $traces as $trace ) {
1011 if ( isset( $trace['file'] ) && false !== strpos( $trace['file'], 'woocommerce' ) ) {
1012 return true;
1013 }
1014 }
1015 return false;
1016 }
1017 }
1018
1019 if ( ! function_exists( 'gglcptch_test_keys' ) ) {
1020 function gglcptch_test_keys() {
1021 global $gglcptch_options;
1022 if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'] , $_REQUEST['action'] ) ) {
1023 header( 'Content-Type: text/html' );
1024 register_gglcptch_settings(); ?>
1025 <p>
1026 <?php if ( 'invisible' == $gglcptch_options['recaptcha_version'] || 'v3' == $gglcptch_options['recaptcha_version'] ) {
1027 _e( 'Please submit "Test verification"', 'google-captcha' );
1028 } else {
1029 _e( 'Please complete the captcha and submit "Test verification"', 'google-captcha' );
1030 } ?>
1031 </p>
1032 <?php echo gglcptch_display(); ?>
1033 <p>
1034 <input type="hidden" name="gglcptch_test_keys_verification-nonce" value="<?php echo wp_create_nonce( 'gglcptch_test_keys_verification' ); ?>" />
1035 <button id="gglcptch_test_keys_verification" name="action" class="button-primary cptch_loading" value="gglcptch_test_keys_verification" disabled="disabled"><?php _e( 'Test verification', 'google-captcha' ); ?></button>
1036 </p>
1037 <?php }
1038 die();
1039 }
1040 }
1041
1042 if ( ! function_exists( 'gglcptch_test_keys_verification' ) ) {
1043 function gglcptch_test_keys_verification() {
1044 if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'] , $_REQUEST['action'] ) ) {
1045 $result = gglcptch_check( 'gglcptch_test', true );
1046
1047 if ( ! $result['response'] ) {
1048 if ( isset( $result['reason'] ) ) {
1049 foreach ( ( array )$result['reason'] as $error ) { ?>
1050 <div class="error gglcptch-test-results"><p>
1051 <?php gglcptch_get_message( $error, true ); ?>
1052 </p></div>
1053 <?php }
1054 }
1055 } else { ?>
1056 <div class="updated gglcptch-test-results"><p><?php _e( 'The verification is successfully completed.','google-captcha' ); ?></p></div>
1057 <?php $gglcptch_options = get_option( 'gglcptch_options' );
1058 $gglcptch_options['keys_verified'] = true;
1059 unset( $gglcptch_options['need_keys_verified_check'] );
1060 update_option( 'gglcptch_options', $gglcptch_options );
1061 }
1062 }
1063 die();
1064 }
1065 }
1066
1067 if ( ! function_exists( 'gglcptch_action_links' ) ) {
1068 function gglcptch_action_links( $links, $file ) {
1069 if ( ! is_network_admin() ) {
1070 static $this_plugin;
1071 if ( ! $this_plugin ) {
1072 $this_plugin = plugin_basename( __FILE__ );
1073 }
1074
1075 if ( $file == $this_plugin ) {
1076 $settings_link = '<a href="admin.php?page=google-captcha.php">' . __( 'Settings', 'google-captcha' ) . '</a>';
1077 array_unshift( $links, $settings_link );
1078 }
1079 }
1080 return $links;
1081 }
1082 }
1083
1084 if ( ! function_exists( 'gglcptch_links' ) ) {
1085 function gglcptch_links( $links, $file ) {
1086 $base = plugin_basename( __FILE__ );
1087 if ( $file == $base ) {
1088 if ( ! is_network_admin() ) {
1089 $links[] = '<a href="admin.php?page=google-captcha.php">' . __( 'Settings', 'google-captcha' ) . '</a>';
1090 }
1091 $links[] = '<a href="https://support.bestwebsoft.com/hc/en-us/sections/200538719" target="_blank">' . __( 'FAQ', 'google-captcha' ) . '</a>';
1092 $links[] = '<a href="https://support.bestwebsoft.com">' . __( 'Support', 'google-captcha' ) . '</a>';
1093 }
1094 return $links;
1095 }
1096 }
1097
1098 if ( ! function_exists ( 'gglcptch_plugin_banner' ) ) {
1099 function gglcptch_plugin_banner() {
1100 global $hook_suffix, $gglcptch_plugin_info, $gglcptch_options;
1101 if ( 'plugins.php' == $hook_suffix ) {
1102 if ( empty( $gglcptch_options ) ) {
1103 register_gglcptch_settings();
1104 }
1105
1106 if ( empty( $gglcptch_options['public_key'] ) || empty( $gglcptch_options['private_key'] ) ) { ?>
1107 <div class="error">
1108 <p>
1109 <?php printf(
1110 '<strong>%s <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s <a target="_blank" href="%s">%s</a>.</strong>',
1111 __( 'To use Google Captcha you must get the keys from', 'google-captcha' ),
1112 __ ( 'here', 'google-captcha' ),
1113 __ ( 'and enter them on the', 'google-captcha' ),
1114 admin_url( '/admin.php?page=google-captcha.php' ),
1115 __( 'plugin setting page', 'google-captcha' )
1116 ); ?>
1117 </p>
1118 </div>
1119 <?php }
1120 if ( isset( $gglcptch_options['first_install'] ) && strtotime( '-1 week' ) > $gglcptch_options['first_install'] ) {
1121 bws_plugin_banner( $gglcptch_plugin_info, 'gglcptch', 'google-captcha', '676d9558f9786ab41d7de35335cf5c4d', '109', '//ps.w.org/google-captcha/assets/icon-128x128.png' );
1122 }
1123
1124 bws_plugin_banner_to_settings( $gglcptch_plugin_info, 'gglcptch_options', 'google-captcha', 'admin.php?page=google-captcha.php' );
1125 }
1126
1127 if ( isset( $_GET['page'] ) && 'google-captcha.php' == $_GET['page'] ) {
1128 bws_plugin_suggest_feature_banner( $gglcptch_plugin_info, 'gglcptch_options', 'google-captcha' );
1129 }
1130 }
1131 }
1132
1133 /* add help tab */
1134 if ( ! function_exists( 'gglcptch_add_tabs' ) ) {
1135 function gglcptch_add_tabs() {
1136 $screen = get_current_screen();
1137 $args = array(
1138 'id' => 'gglcptch',
1139 'section' => '200538719'
1140 );
1141 bws_help_tab( $screen, $args );
1142 }
1143 }
1144
1145 if ( ! function_exists( 'gglcptch_delete_options' ) ) {
1146 function gglcptch_delete_options() {
1147 if ( ! function_exists( 'get_plugins' ) ) {
1148 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
1149 }
1150 $all_plugins = get_plugins();
1151
1152 if ( ! array_key_exists( 'google-captcha-pro/google-captcha-pro.php', $all_plugins ) ) {
1153 global $wpdb;
1154 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
1155 $old_blog = $wpdb->blogid;
1156 /* Get all blog ids */
1157 $blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" );
1158 foreach ( $blogids as $blog_id ) {
1159 switch_to_blog( $blog_id );
1160 $wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}gglcptch_whitelist`;" );
1161 delete_option( 'gglcptch_options' );
1162 }
1163 switch_to_blog( $old_blog );
1164 delete_site_option( 'gglcptch_options' );
1165 } else {
1166 $wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}gglcptch_whitelist`;" );
1167 delete_option( 'gglcptch_options' );
1168 }
1169 }
1170
1171 require_once( dirname( __FILE__ ) . '/bws_menu/bws_include.php' );
1172 bws_include_init( plugin_basename( __FILE__ ) );
1173 bws_delete_plugin( plugin_basename( __FILE__ ) );
1174 }
1175 }
1176
1177 register_activation_hook( __FILE__, 'gglcptch_plugin_activate' );
1178
1179 add_action( 'admin_menu', 'gglcptch_admin_menu' );
1180
1181 add_action( 'init', 'gglcptch_init' );
1182 add_action( 'admin_init', 'gglcptch_admin_init' );
1183
1184 add_action( 'plugins_loaded', 'gglcptch_plugins_loaded' );
1185
1186 add_action( 'admin_enqueue_scripts', 'gglcptch_add_admin_script_styles' );
1187 add_filter( 'script_loader_tag', 'gglcptch_add_async_attribute', 10, 2 );
1188 add_action( 'admin_footer', 'gglcptch_admin_footer' );
1189 add_filter( 'pgntn_callback', 'gglcptch_pagination_callback' );
1190
1191 add_filter( 'lmtttmpts_plugin_forms', 'gglcptch_add_lmtttmpts_forms', 10, 1 );
1192
1193 add_shortcode( 'bws_google_captcha', 'gglcptch_display' );
1194 add_filter( 'widget_text', 'do_shortcode' );
1195
1196 add_filter( 'gglcptch_display_recaptcha', 'gglcptch_display_custom', 10, 2 );
1197 add_filter( 'gglcptch_verify_recaptcha', 'gglcptch_check_custom', 10, 3 );
1198
1199 add_filter( 'gglcptch_limit_attempts_check', 'gglcptch_limit_attempts_check', 10, 2 );
1200
1201 add_filter( 'plugin_action_links', 'gglcptch_action_links', 10, 2 );
1202 add_filter( 'plugin_row_meta', 'gglcptch_links', 10, 2 );
1203
1204 add_action( 'admin_notices', 'gglcptch_plugin_banner' );
1205
1206 add_action( 'wp_ajax_gglcptch-test-keys', 'gglcptch_test_keys' );
1207 add_action( 'wp_ajax_gglcptch_test_keys_verification', 'gglcptch_test_keys_verification' );
1208