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