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