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