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