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