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