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