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