PluginProbe ʕ •ᴥ•ʔ
reCaptcha by BestWebSoft / 1.22
reCaptcha by BestWebSoft v1.22
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 10 years ago css 10 years ago images 10 years ago js 10 years ago languages 10 years ago lib 10 years ago google-captcha.php 10 years ago readme.txt 10 years ago screenshot-1.png 10 years ago screenshot-2.png 10 years ago screenshot-3.png 10 years ago screenshot-4.png 10 years ago screenshot-5.png 10 years ago screenshot-6.png 10 years ago screenshot-7.png 10 years ago screenshot-8.png 10 years ago
google-captcha.php
1144 lines
1 <?php
2 /*
3 Plugin Name: Google Captcha (reCAPTCHA) by BestWebSoft
4 Plugin URI: http://bestwebsoft.com/products/
5 Description: Plugin Google Captcha intended to prove that the visitor is a human being and not a spam robot.
6 Author: BestWebSoft
7 Text Domain: google-captcha
8 Domain Path: /languages
9 Version: 1.22
10 Author URI: http://bestwebsoft.com/
11 License: GPLv3 or later
12 */
13
14 /* © Copyright 2016 BestWebSoft ( http://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 /* Add menu page */
30 if ( ! function_exists( 'gglcptch_admin_menu' ) ) {
31 function gglcptch_admin_menu() {
32 bws_general_menu();
33 $gglcptch_settings = add_submenu_page( 'bws_plugins', __( 'Google Captcha Settings', 'google-captcha' ), 'Google Captcha', 'manage_options', 'google-captcha.php', 'gglcptch_settings_page' );
34 add_action( 'load-' . $gglcptch_settings, 'gglcptch_add_tabs' );
35 }
36 }
37
38 if ( ! function_exists( 'gglcptch_plugins_loaded' ) ) {
39 function gglcptch_plugins_loaded() {
40 /* Internationalization, first(!) */
41 load_plugin_textdomain( 'google-captcha', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
42 }
43 }
44
45 /* Get option from the php.ini */
46 if ( ! function_exists( 'gglcptch_get_allow_url_fopen' ) ) {
47 function gglcptch_get_allow_url_fopen() {
48 return ( ini_get( 'allow_url_fopen' ) != 1 ) ? false : true;
49 }
50 }
51
52 if ( ! function_exists( 'gglcptch_init' ) ) {
53 function gglcptch_init() {
54 global $gglcptch_plugin_info;
55
56 require_once( dirname( __FILE__ ) . '/bws_menu/bws_include.php' );
57 bws_include_init( plugin_basename( __FILE__ ) );
58
59 if ( empty( $gglcptch_plugin_info ) ) {
60 if ( ! function_exists( 'get_plugin_data' ) )
61 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
62 $gglcptch_plugin_info = get_plugin_data( __FILE__ );
63 }
64
65 /* Function check if plugin is compatible with current WP version */
66 bws_wp_min_version_check( plugin_basename( __FILE__ ), $gglcptch_plugin_info, '3.8', '3.1' );
67 }
68 }
69
70 if ( ! function_exists( 'gglcptch_admin_init' ) ) {
71 function gglcptch_admin_init() {
72 global $bws_plugin_info, $gglcptch_plugin_info, $bws_shortcode_list;
73
74 if ( ! isset( $bws_plugin_info ) || empty( $bws_plugin_info ) )
75 $bws_plugin_info = array( 'id' => '109', 'version' => $gglcptch_plugin_info["Version"] );
76
77 /* Call register settings function */
78 if ( isset( $_GET['page'] ) && "google-captcha.php" == $_GET['page'] )
79 register_gglcptch_settings();
80
81 /* add google captcha to global $bws_shortcode_list */
82 $bws_shortcode_list['gglcptch'] = array( 'name' => 'Google Captcha (reCAPTCHA)', 'js_function' => 'gglcptch_shortcode_init' );
83 }
84 }
85
86 /* Add google captcha styles */
87 if ( ! function_exists( 'gglcptch_add_admin_script_styles' ) ) {
88 function gglcptch_add_admin_script_styles() {
89 if ( isset( $_REQUEST['page'] ) && 'google-captcha.php' == $_REQUEST['page'] ) {
90 wp_enqueue_style( 'gglcptch_stylesheet', plugins_url( 'css/style.css', __FILE__ ) );
91 wp_enqueue_script( 'gglcptch_admin_script', plugins_url( 'js/admin_script.js', __FILE__ ), array( 'jquery' ) );
92 }
93 }
94 }
95
96 /**
97 * Remove dublicate scripts
98 */
99 if ( ! function_exists( 'gglcptch_remove_dublicate_scripts' ) ) {
100 function gglcptch_remove_dublicate_scripts() {
101 global $wp_scripts;
102
103 if ( ! is_object( $wp_scripts ) || empty( $wp_scripts ) )
104 return false;
105
106 foreach( $wp_scripts->registered as $script_name => $args ) {
107 if ( preg_match( "|google\.com/recaptcha/api\.js|", $args->src ) && 'gglcptch_api' != $script_name )
108 /* remove a previously enqueued script */
109 wp_dequeue_script( $script_name );
110 }
111 }
112 }
113
114 /**
115 * Add google captcha styles
116 */
117 if ( ! function_exists( 'gglcptch_add_styles' ) ) {
118 function gglcptch_add_styles() {
119 global $gglcptch_plugin_info;
120 wp_enqueue_style( 'gglcptch', plugins_url( 'css/gglcptch.css', __FILE__ ), false, $gglcptch_plugin_info["Version"] );
121 }
122 }
123
124 /**
125 * Add google captcha js scripts
126 */
127 if ( ! function_exists( 'gglcptch_add_scripts' ) ) {
128 function gglcptch_add_scripts() {
129 global $gglcptch_plugin_info, $gglcptch_options;
130
131 if ( empty( $gglcptch_options ) )
132 $gglcptch_options = get_option( 'gglcptch_options' );
133
134 if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] )
135 gglcptch_remove_dublicate_scripts();
136
137 wp_enqueue_script( 'gglcptch_script', plugins_url( 'js/script.js', __FILE__ ), array( 'jquery', 'gglcptch_api' ), $gglcptch_plugin_info["Version"], true );
138
139 $version = $gglcptch_options['recaptcha_version'] == 'v2' ? '_v2' : '';
140
141 wp_localize_script( 'gglcptch_script', 'gglcptch', array(
142 'options' => array(
143 'version' => $gglcptch_options['recaptcha_version'],
144 'sitekey' => $gglcptch_options['public_key'],
145 'theme' => $gglcptch_options[ 'theme' . $version ],
146 'error' => "<strong>" . __( 'Warning', 'google-captcha' ) . ":</strong>&nbsp;" . __( 'It has been found more than one reCAPTCHA in current form. In this case reCAPTCHA will not work properly. Please remove all unnecessary reCAPTCHA blocks.', 'google-captcha' )
147 ),
148 'vars' => array(
149 'ajaxurl' => admin_url( 'admin-ajax.php' ),
150 'error_msg' => __( 'Error: You have entered an incorrect reCAPTCHA value.', 'google-captcha' ),
151 'nonce' => wp_create_nonce( 'gglcptch_recaptcha_nonce' )
152 )
153 ) );
154 }
155 }
156
157 /**
158 * Add the "async" attribute to our registered script.
159 */
160 if ( ! function_exists( 'gglcptch_add_async_attribute' ) ) {
161 function gglcptch_add_async_attribute( $tag, $handle ) {
162 if ( 'gglcptch_api' == $handle )
163 $tag = str_replace( ' src', ' async="async" defer="defer" src', $tag );
164 return $tag;
165 }
166 }
167
168 /* Google catpcha settings */
169 if ( ! function_exists( 'register_gglcptch_settings' ) ) {
170 function register_gglcptch_settings() {
171 global $gglcptch_options, $bws_plugin_info, $gglcptch_plugin_info, $gglcptch_default_options;
172
173 $gglcptch_default_options = array(
174 'public_key' => '',
175 'private_key' => '',
176 'login_form' => '1',
177 'registration_form' => '1',
178 'reset_pwd_form' => '1',
179 'comments_form' => '1',
180 'contact_form' => '0',
181 'theme' => 'red',
182 'theme_v2' => 'light',
183 'recaptcha_version' => ( gglcptch_get_allow_url_fopen() ) ? 'v2' : 'v1',
184 'plugin_option_version' => $gglcptch_plugin_info["Version"],
185 'first_install' => strtotime( "now" ),
186 'display_settings_notice' => 1
187 );
188
189 if ( function_exists( 'get_editable_roles' ) ) {
190 foreach ( get_editable_roles() as $role => $fields ) {
191 $gglcptch_default_options[ $role ] = '0';
192 }
193 }
194
195 /* Install the option defaults */
196 if ( ! get_option( 'gglcptch_options' ) )
197 add_option( 'gglcptch_options', $gglcptch_default_options );
198 /* Get options from the database */
199 $gglcptch_options = get_option( 'gglcptch_options' );
200
201 /* Array merge incase this version has added new options */
202 if ( ! isset( $gglcptch_options['plugin_option_version'] ) || $gglcptch_options['plugin_option_version'] != $gglcptch_plugin_info["Version"] ) {
203 $gglcptch_default_options['display_settings_notice'] = 0;
204 $gglcptch_options = array_merge( $gglcptch_default_options, $gglcptch_options );
205 $gglcptch_options['plugin_option_version'] = $gglcptch_plugin_info["Version"];
206 /* show pro features */
207 $gglcptch_options['hide_premium_options'] = array();
208 update_option( 'gglcptch_options', $gglcptch_options );
209 }
210 }
211 }
212
213 global $gglcptch_options;
214 if ( ! $gglcptch_options ) {
215 $gglcptch_options = get_option( 'gglcptch_options' );
216 if ( ! $gglcptch_options ) {
217 register_gglcptch_settings();
218 $gglcptch_options = get_option( 'gglcptch_options' );
219 }
220 }
221
222 /* Add hooks */
223 if ( '1' == $gglcptch_options['login_form'] || '1' == $gglcptch_options['reset_pwd_form'] || '1' == $gglcptch_options['registration_form'] ) {
224 add_action( 'login_enqueue_scripts', 'gglcptch_add_styles' );
225
226 if ( '1' == $gglcptch_options['login_form'] ) {
227 add_action( 'login_form', 'gglcptch_login_display' );
228 add_action( 'authenticate', 'gglcptch_login_check', 21, 1 );
229 }
230
231 if ( '1' == $gglcptch_options['reset_pwd_form'] ) {
232 add_action( 'lostpassword_form', 'gglcptch_login_display' );
233 add_action( 'allow_password_reset', 'gglcptch_lostpassword_check' );
234 }
235
236 if ( '1' == $gglcptch_options['registration_form'] ) {
237 if ( ! is_multisite() ) {
238 add_action( 'register_form', 'gglcptch_login_display' );
239 add_action( 'registration_errors', 'gglcptch_lostpassword_check' );
240 } else {
241 add_action( 'signup_extra_fields', 'gglcptch_signup_display' );
242 add_action( 'signup_blogform', 'gglcptch_signup_display' );
243 add_filter( 'wpmu_validate_user_signup', 'gglcptch_signup_check' );
244 }
245 }
246 }
247
248 if ( '1' == $gglcptch_options['comments_form'] ) {
249 add_action( 'comment_form_after_fields', 'gglcptch_commentform_display' );
250 add_action( 'comment_form_logged_in_after', 'gglcptch_commentform_display' );
251 add_action( 'pre_comment_on_post', 'gglcptch_commentform_check' );
252 }
253
254 if ( '1' == $gglcptch_options['contact_form'] ) {
255 add_filter( 'cntctfrm_display_captcha', 'gglcptch_cf_display', 10, 2 );
256 add_filter( 'cntctfrmpr_display_captcha', 'gglcptch_cf_display', 10, 2 );
257 add_filter( 'cntctfrm_check_form', 'gglcptch_recaptcha_check' );
258 add_filter( 'cntctfrmpr_check_form', 'gglcptch_recaptcha_check' );
259 }
260
261 if ( ! function_exists( 'gglcptch_plugin_status' ) ) {
262 function gglcptch_plugin_status( $plugins, $all_plugins, $is_network ) {
263 $result = array(
264 'status' => '',
265 'plugin' => '',
266 'plugin_info' => array(),
267 );
268 foreach ( (array)$plugins as $plugin ) {
269 if ( array_key_exists( $plugin, $all_plugins ) ) {
270 if (
271 ( $is_network && is_plugin_active_for_network( $plugin ) ) ||
272 ( ! $is_network && is_plugin_active( $plugin ) )
273 ) {
274 $result['status'] = 'actived';
275 $result['plugin'] = $plugin;
276 $result['plugin_info'] = $all_plugins[$plugin];
277 break;
278 } else {
279 $result['status'] = 'deactivated';
280 $result['plugin'] = $plugin;
281 $result['plugin_info'] = $all_plugins[$plugin];
282 }
283
284 }
285 }
286 if ( empty( $result['status'] ) )
287 $result['status'] = 'not_installed';
288 return $result;
289 }
290 }
291
292 /* Display settings page */
293 if ( ! function_exists( 'gglcptch_settings_page' ) ) {
294 function gglcptch_settings_page() {
295 global $gglcptch_options, $gglcptch_plugin_info, $wp_version, $gglcptch_default_options;
296
297 $plugin_basename = plugin_basename( __FILE__ );
298 $message = $error = '';
299
300 $all_plugins = get_plugins();
301 $is_network = is_multisite() && is_network_admin();
302 $is_main_site = is_main_site( get_current_blog_id() );
303 $admin_url = $is_network ? network_admin_url( '/' ) : admin_url( '/' );
304 $bws_contact_form = gglcptch_plugin_status( array( 'contact-form-plugin/contact_form.php', 'contact-form-pro/contact_form_pro.php' ), $all_plugins, $is_network );
305
306 if ( ! isset( $_GET['action'] ) ) {
307
308 $all_plugins = get_plugins();
309
310 $gglcptch_sizes_v2 = array(
311 'normal' => __( 'Normal', 'google-captcha' ),
312 'compact' => __( 'Compact', 'google-captcha' )
313 );
314
315 /* Private and public keys */
316 $gglcptch_keys = array(
317 'public' => array(
318 'display_name' => __( 'Site key', 'google-captcha' ),
319 'form_name' => 'gglcptch_public_key',
320 'error_msg' => '',
321 ),
322 'private' => array(
323 'display_name' => __( 'Secret Key', 'google-captcha' ),
324 'form_name' => 'gglcptch_private_key',
325 'error_msg' => '',
326 ),
327 );
328
329 /* Checked forms */
330 $gglcptch_forms = array(
331 array( 'login_form', __( 'Login form', 'google-captcha' ) ),
332 array( 'registration_form', __( 'Registration form', 'google-captcha' ) ),
333 array( 'reset_pwd_form', __( 'Reset password form', 'google-captcha' ) ),
334 array( 'comments_form', __( 'Comments form', 'google-captcha' ) ),
335 );
336
337 /* Google captcha themes */
338 $gglcptch_themes = array(
339 array( 'red', 'Red' ),
340 array( 'white', 'White' ),
341 array( 'blackglass', 'Blackglass' ),
342 array( 'clean', 'Clean' ),
343 );
344
345 /* Save data for settings page */
346 if ( isset( $_POST['gglcptch_form_submit'] ) && check_admin_referer( $plugin_basename, 'gglcptch_nonce_name' ) ) {
347 if ( isset( $_POST['bws_hide_premium_options'] ) ) {
348 $hide_result = bws_hide_premium_options( $gglcptch_options );
349 $gglcptch_options = $hide_result['options'];
350 }
351
352 if ( ! $_POST['gglcptch_public_key'] || '' == $_POST['gglcptch_public_key'] ) {
353 $gglcptch_keys['public']['error_msg'] = __( 'Enter site key', 'google-captcha' );
354 $error = __( "WARNING: The captcha will not display while you don't fill key fields.", 'google-captcha' );
355 } else
356 $gglcptch_keys['public']['error_msg'] = '';
357
358 if ( ! $_POST['gglcptch_private_key'] || '' == $_POST['gglcptch_private_key'] ) {
359 $gglcptch_keys['private']['error_msg'] = __( 'Enter secret key', 'google-captcha' );
360 $error = __( "WARNING: The captcha will not display while you don't fill key fields.", 'google-captcha' );
361 } else
362 $gglcptch_keys['private']['error_msg'] = '';
363
364 $gglcptch_options['public_key'] = trim( stripslashes( esc_html( $_POST['gglcptch_public_key'] ) ) );
365 $gglcptch_options['private_key'] = trim( stripslashes( esc_html( $_POST['gglcptch_private_key'] ) ) );
366 $gglcptch_options['login_form'] = isset( $_POST['gglcptch_login_form'] ) ? 1 : 0;
367 $gglcptch_options['registration_form'] = isset( $_POST['gglcptch_registration_form'] ) ? 1 : 0;
368 $gglcptch_options['reset_pwd_form'] = isset( $_POST['gglcptch_reset_pwd_form'] ) ? 1 : 0;
369 $gglcptch_options['comments_form'] = isset( $_POST['gglcptch_comments_form'] ) ? 1 : 0;
370 $gglcptch_options['contact_form'] = isset( $_POST['gglcptch_contact_form'] ) ? 1 : 0;
371 $gglcptch_options['recaptcha_version'] = $_POST['gglcptch_recaptcha_version'];
372 $gglcptch_options['theme'] = $_POST['gglcptch_theme'];
373 $gglcptch_options['theme_v2'] = $_POST['gglcptch_theme_v2'];
374
375 if ( function_exists( 'get_editable_roles' ) ) {
376 foreach ( get_editable_roles() as $role => $fields ) {
377 $gglcptch_options[ $role ] = isset( $_POST[ 'gglcptch_' . $role ] ) ? 1 : 0;
378 }
379 }
380
381 update_option( 'gglcptch_options', $gglcptch_options );
382 $message = __( 'Settings saved', 'google-captcha' );
383 }
384
385 if ( isset( $_REQUEST['bws_restore_confirm'] ) && check_admin_referer( $plugin_basename, 'bws_settings_nonce_name' ) ) {
386 $gglcptch_options = $gglcptch_default_options;
387 update_option( 'gglcptch_options', $gglcptch_options );
388 $message = __( 'All plugin settings were restored.', 'google-captcha' );
389 }
390 }
391
392 $bws_hide_premium_options_check = bws_hide_premium_options_check( $gglcptch_options );
393
394 /* GO PRO */
395 if ( isset( $_GET['action'] ) && 'go_pro' == $_GET['action'] ) {
396 $go_pro_result = bws_go_pro_tab_check( $plugin_basename, 'gglcptch_options' );
397 if ( ! empty( $go_pro_result['error'] ) )
398 $error = $go_pro_result['error'];
399 elseif ( ! empty( $go_pro_result['message'] ) )
400 $message = $go_pro_result['message'];
401 } ?>
402 <div class="wrap">
403 <h1 style="line-height: normal;"><?php _e( 'Google Captcha Settings', 'google-captcha' ); ?></h1>
404 <h2 class="nav-tab-wrapper">
405 <a class="nav-tab<?php if ( ! isset( $_GET['action'] ) ) echo ' nav-tab-active'; ?>" href="admin.php?page=google-captcha.php"><?php _e( 'Settings', 'google-captcha' ); ?></a>
406 <a class="nav-tab<?php if ( isset( $_GET['action'] ) && 'go_pro' == $_GET['action'] ) echo ' nav-tab-active'; ?> bws_go_pro_tab" href="admin.php?page=google-captcha.php&amp;action=go_pro"><?php _e( 'Go PRO', 'google-captcha' ); ?></a>
407 </h2>
408 <?php if ( ! isset( $_GET['action'] ) && ! isset( $_REQUEST['bws_restore_default'] ) ) {
409 if ( ! gglcptch_get_allow_url_fopen() && $gglcptch_options['recaptcha_version'] == 'v2' ) {
410 printf( '<div class="error inline"><p><strong>%s</strong></p></div>',
411 __( 'Google Captcha version 2 will not work correctly, since the option "allow_url_fopen" is disabled. Please contact your hosting support service.', 'google-captcha' )
412 );
413 }
414 if ( $gglcptch_options['recaptcha_version'] == 'v1' ) {
415 printf( '<div id="gglcptch_v1_notice" class="updated inline"><p><strong>%s</strong></p></div>',
416 __( "Only one reCAPTCHA can be displayed on the page, it's related to reCAPTCHA version 1 features.", 'google-captcha' )
417 );
418 }
419 }
420 bws_show_settings_notice(); ?>
421 <div class="updated fade inline" <?php if ( "" == $message ) echo 'style="display:none"'; ?>><p><strong><?php echo $message; ?></strong></p></div>
422 <div class="error inline" <?php if ( "" == $error ) echo 'style="display:none"'; ?>><p><strong><?php echo $error; ?></strong></p></div>
423 <?php if ( ! empty( $hide_result['message'] ) ) { ?>
424 <div class="updated fade inline"><p><strong><?php echo $hide_result['message']; ?></strong></p></div>
425 <?php }
426 if ( ! isset( $_GET['action'] ) ) {
427 if ( isset( $_REQUEST['bws_restore_default'] ) && check_admin_referer( $plugin_basename, 'bws_settings_nonce_name' ) ) {
428 bws_form_restore_default_confirm( $plugin_basename );
429 } else { ?>
430 <div style="margin: 20px 0;">
431 <?php printf( __( "If you would like to add a Google Captcha (reCAPTCHA) to your page or post, please use %s button", 'google-captcha' ),
432 '<span class="bws_code"><img style="vertical-align: sub;" src="' . plugins_url( 'bws_menu/images/shortcode-icon.png', __FILE__ ) . '" alt=""/></span>'
433 ); ?>
434 <div class="bws_help_box bws_help_box_right dashicons dashicons-editor-help" style="vertical-align: middle;">
435 <div class="bws_hidden_help_text" style="min-width: 260px;">
436 <?php printf(
437 __( "You can add the Google Captcha (reCAPTCHA) to your page or post by clicking on %s button in the content edit block using the Visual mode. If the button isn't displayed or you would like to add the Google Captcha (reCAPTCHA) to your own form , please use the shortcode %s", 'google-captcha' ),
438 '<code><img style="vertical-align: sub;" src="' . plugins_url( 'bws_menu/images/shortcode-icon.png', __FILE__ ) . '" alt="" /></code>',
439 sprintf( '<span class="bws_code">[bws_google_captcha]</span><br/>' )
440 ); ?>
441 </div>
442 </div>
443 </div>
444 <form class="bws_form" method="post" action="admin.php?page=google-captcha.php">
445 <h3><?php _e( 'Authentication', 'google-captcha' ); ?></h3>
446 <p><?php printf( __( 'Before you are able to do something, you must to register %shere%s', 'google-captcha' ), '<a target="_blank" href="https://www.google.com/recaptcha/admin#list">','</a>.' ); ?></p>
447 <p><?php _e( 'Enter site key and secret key, that you get after registration.', 'google-captcha' ); ?></p>
448 <table id="gglcptch-keys" class="form-table">
449 <?php foreach ( $gglcptch_keys as $key => $fields ) { ?>
450 <tr valign="top">
451 <th scope="row"><?php echo $fields['display_name']; ?></th>
452 <td>
453 <input type="text" name="<?php echo $fields['form_name']; ?>" value="<?php echo $gglcptch_options[ $key . '_key' ] ?>" maxlength="200" />
454 <label class="gglcptch_error_msg"><?php echo $fields['error_msg']; ?></label>
455 </td>
456 </tr>
457 <?php } ?>
458 </table>
459 <h3><?php _e( 'Options', 'google-captcha' ); ?></h3>
460 <table class="form-table">
461 <tr valign="top">
462 <th scope="row"><?php _e( 'Enable reCAPTCHA for', 'google-captcha' ); ?></th>
463 <td>
464 <fieldset>
465 <p>
466 <i><?php _e( 'WordPress default', 'google-captcha' ); ?></i>
467 </p>
468 <?php foreach ( $gglcptch_forms as $form ) {
469 $gglcptch_form_type = $form[0];
470 $gglcptch_form_name = $form[1];
471 $gglcptch_form_attr = ( '1' == $gglcptch_options[ $gglcptch_form_type ] ) ? 'checked="checked"' : '';
472 $gglcptch_form_notice = '';
473
474 if ( ( $gglcptch_form_type == 'registration_form' || $gglcptch_form_type == 'reset_pwd_form' ) && ! $is_main_site ) {
475 $gglcptch_form_notice .= sprintf( '<span class="bws_info">%s</span>', __( 'This option is available only for network or for main blog', 'google-captcha' ) );
476 $gglcptch_form_attr = 'disabled="disabled" readonly="readonly"';
477 } ?>
478 <label><input type="checkbox" name="<?php echo 'gglcptch_' . $gglcptch_form_type; ?>" value="<?php echo $gglcptch_form_type; ?>" <?php echo $gglcptch_form_attr; ?> /> <?php echo $gglcptch_form_name; ?></label>
479 <div class="bws_help_box dashicons dashicons-editor-help" style="vertical-align: middle;"><div class="bws_hidden_help_text"><img src="<?php echo plugins_url( 'google-captcha/images') . '/' . $gglcptch_form_type; ?>.jpg" title="<?php echo $gglcptch_form_name; ?>" alt="<?php echo $gglcptch_form_name; ?>"></div></div> <?php echo $gglcptch_form_notice; ?><br />
480 <?php } ?>
481 <br />
482 <p>
483 <i><?php _e( 'Plugins', 'google-captcha' ); ?></i>
484 </p>
485 <?php /* Check Contact Form by BestWebSoft */
486 $gglcptch_plugin = $bws_contact_form;
487 $gglcptch_plugin_name = 'Contact Form by BestWebSoft';
488 $gglcptch_attrs = $gglcptch_plugin_notice = '';
489 if ( 'deactivated' == $gglcptch_plugin['status'] ) {
490 $gglcptch_attrs = 'disabled="disabled"';
491 $gglcptch_plugin_notice = sprintf( __( 'You should %s to use this functionality', 'google-captcha' ),
492 sprintf( '<a href="%splugins.php">%s%s %s</a>', $admin_url, __( 'activate', 'google-captcha' ), ( is_network_admin() ? ' ' . __( 'for network', 'google-captcha' ) : '' ), $gglcptch_plugin_name )
493 );
494 } elseif ( 'not_installed' == $gglcptch_plugin['status'] ) {
495 $gglcptch_attrs = 'disabled="disabled"';
496 $gglcptch_plugin_notice = sprintf( __( 'You should %s to use this functionality', 'google-captcha' ),
497 sprintf( '<a href="http://bestwebsoft.com/products/contact-form/?k=d70b58e1739ab4857d675fed2213cedc&pn=75&v=%s&wp_v=%s">%s %s</a>', $gglcptch_plugin_info["Version"], $wp_version, __( 'download', 'google-captcha' ), $gglcptch_plugin_name )
498 );
499 }
500 if ( '1' == $gglcptch_options['contact_form'] && $gglcptch_attrs == '' ) {
501 $gglcptch_attrs .= ' checked="checked"';
502 } ?>
503 <label><input type="checkbox" <?php echo $gglcptch_attrs; ?> name="gglcptch_contact_form" value="contact_form" /> <?php echo $gglcptch_plugin_name; ?></label>
504 <div class="bws_help_box dashicons dashicons-editor-help" style="vertical-align: middle;"><div class="bws_hidden_help_text"><img src="<?php echo plugins_url( 'google-captcha/images'); ?>/contact_form.jpg" title="<?php echo $gglcptch_plugin_name; ?>" alt="<?php echo $gglcptch_plugin_name; ?>"></div></div>
505 <span class="bws_info"><?php echo $gglcptch_plugin_notice; ?></span><br />
506 <?php if ( ! $bws_hide_premium_options_check ) { ?>
507 <div class="bws_pro_version_bloc">
508 <div class="bws_pro_version_table_bloc">
509 <button type="submit" name="bws_hide_premium_options" class="notice-dismiss bws_hide_premium_options" title="<?php _e( 'Close', 'google-captcha' ); ?>"></button>
510 <div class="bws_table_bg"></div>
511 <div class="bws_pro_version">
512 <label><input disabled="disabled" type="checkbox" disabled="disabled" name="gglcptch_sbscrbr" value="1"> Subscriber by BestWebSoft</label><br>
513 <label><input disabled="disabled" type="checkbox" disabled="disabled" name="gglcptch_cf7" value="1"> Contact Form 7</label><br>
514 <label><input disabled="disabled" type="checkbox" disabled="disabled" name="gglcptch_buddypress_register" value="1"> BuddyPress Registration form</label><br>
515 <label><input disabled="disabled" type="checkbox" disabled="disabled" name="gglcptch_buddypress_comments" value="1"> BuddyPress Comments form</label><br>
516 <label><input disabled="disabled" type="checkbox" disabled="disabled" name="gglcptch_buddypress_group" value="1"> BuddyPress "Create a Group" form</label>
517 </div>
518 </div>
519 <div class="bws_pro_version_tooltip">
520 <div class="bws_info">
521 <?php _e( 'Unlock premium options by upgrading to Pro version', 'google-captcha' ); ?>
522 </div>
523 <a class="bws_button" href="http://bestwebsoft.com/products/google-captcha/?k=b850d949ccc1239cab0da315c3c822ab&pn=109&v=<?php echo $gglcptch_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="Google Captcha Pro (reCAPTCHA)">
524 <?php _e( 'Learn More', 'google-captcha' ); ?>
525 </a>
526 <div class="clear"></div>
527 </div>
528 </div><br>
529 <?php } ?>
530 <span class="bws_info"><?php printf( __( 'If you would like to add Google Captcha (reCAPTCHA) to a custom form see %s', 'google-captcha' ), sprintf( '<a href="http://bestwebsoft.com/products/google-captcha/faq/" target="_blank">%s</a>', __( 'FAQ', 'google-captcha' ) ) ); ?></span>
531 </fieldset>
532 </td>
533 </tr>
534 <tr valign="top">
535 <th scope="row"><?php _e( 'Hide reCAPTCHA in Comments form for', 'google-captcha' ); ?></th>
536 <td>
537 <fieldset>
538 <?php if ( function_exists( 'get_editable_roles' ) ) {
539 foreach ( get_editable_roles() as $role => $fields) : ?>
540 <label><input type="checkbox" name="<?php echo 'gglcptch_' . $role; ?>" value=<?php echo $role; if ( isset( $gglcptch_options[ $role ] ) && '1' == $gglcptch_options[ $role ] ) echo ' checked'; ?>> <?php echo $fields['name']; ?></label><br/>
541 <?php endforeach;
542 } ?>
543 </fieldset>
544 </td>
545 </tr>
546 <tr valign="top">
547 <th scope="row"><?php _e( 'reCAPTCHA version', 'google-captcha' ); ?></th>
548 <td>
549 <fieldset>
550 <label><input type="radio" name="gglcptch_recaptcha_version" value="v1"<?php if ( 'v1' == $gglcptch_options['recaptcha_version'] ) echo ' checked="checked"'; ?>> <?php _e( 'version', 'google-captcha' ); ?> 1</label>
551 <div class="bws_help_box dashicons dashicons-editor-help" style="vertical-align: middle;"><div class="bws_hidden_help_text"><img src="<?php echo plugins_url( 'google-captcha/images'); ?>/recaptcha_v1.png" title="reCAPTCHA <?php _e( 'version', 'google-captcha' ); ?> 1" alt="reCAPTCHA <?php _e( 'version', 'google-captcha' ); ?> 1"></div></div><br/>
552 <label><input type="radio" name="gglcptch_recaptcha_version" value="v2"<?php if ( 'v2' == $gglcptch_options['recaptcha_version'] ) echo ' checked="checked"'; ?>> <?php _e( 'version', 'google-captcha' ); ?> 2</label>
553 <div class="bws_help_box dashicons dashicons-editor-help" style="vertical-align: middle;"><div class="bws_hidden_help_text"><img src="<?php echo plugins_url( 'google-captcha/images'); ?>/recaptcha_v2.png" title="reCAPTCHA <?php _e( 'version', 'google-captcha' ); ?> 2" alt="reCAPTCHA <?php _e( 'version', 'google-captcha' ); ?> 2"></div></div>
554 </fieldset>
555 </td>
556 </tr>
557 <tr class="gglcptch_theme_v1" valign="top">
558 <th scope="row">
559 <?php _e( 'reCAPTCHA theme', 'google-captcha' ); ?>
560 <br/><span class="bws_info">(<?php _e( 'for version', 'google-captcha' ); ?> 1)</span>
561 </th>
562 <td>
563 <select name="gglcptch_theme">
564 <?php foreach ( $gglcptch_themes as $theme ) : ?>
565 <option value=<?php echo $theme[0]; if ( $theme[0] == $gglcptch_options['theme'] ) echo ' selected'; ?>> <?php echo $theme[1]; ?></option>
566 <?php endforeach; ?>
567 </select>
568 </td>
569 </tr>
570 <tr class="gglcptch_theme_v2" valign="top">
571 <th scope="row">
572 <?php _e( 'reCAPTCHA theme', 'google-captcha' ); ?>
573 <br/><span class="bws_info">(<?php _e( 'for version', 'google-captcha' ); ?> 2)</span>
574 </th>
575 <td>
576 <select name="gglcptch_theme_v2">
577 <option value="light" <?php if ( 'light' == $gglcptch_options['theme_v2'] ) echo ' selected'; ?>>light</option>
578 <option value="dark" <?php if ( 'dark' == $gglcptch_options['theme_v2'] ) echo ' selected'; ?>>dark</option>
579 </select>
580 </td>
581 </tr>
582 </table>
583 <?php if ( ! $bws_hide_premium_options_check ) { ?>
584 <div class="bws_pro_version_bloc">
585 <div class="bws_pro_version_table_bloc">
586 <button type="submit" name="bws_hide_premium_options" class="notice-dismiss bws_hide_premium_options" title="<?php _e( 'Close', 'google-captcha' ); ?>"></button>
587 <div class="bws_table_bg"></div>
588 <table class="form-table bws_pro_version">
589 <tr valign="top">
590 <th scope="row"><?php _e( 'reCAPTCHA language', 'google-captcha' ); ?></th>
591 <td>
592 <select disabled="disabled" name="gglcptch_language">
593 <option value="en" selected="selected">English (US)</option>
594 </select>
595 <div style="margin: 5px 0 0;">
596 <input disabled="disabled" id="gglcptch_use_multilanguage_locale" type="checkbox" name="gglcptch_use_multilanguage_locale" value="1" />
597 <label for="gglcptch_use_multilanguage_locale"><?php _e( 'Use the current site language', 'google-captcha' ); ?></label>&nbsp;<span class="bws_info">(<?php _e( 'Using', 'google-captcha' ); ?> Multilanguage by BestWebSoft)</span>
598 </div>
599 </td>
600 </tr>
601 <tr valign="top">
602 <th scope="row">
603 <?php _e( 'reCAPTCHA size', 'google-captcha' ); ?>
604 <br/><span class="bws_info">(<?php _e( 'for version', 'google-captcha' ); ?> 2)</span>
605 </th>
606 <td><fieldset>
607 <?php foreach ( $gglcptch_sizes_v2 as $value => $name ) {
608 printf(
609 '<div class="gglcptch_size_v2"><label><input disabled="disabled" type="radio" name="gglcptch_size_v2" value="%s"%s> %s</label></div>',
610 $value,
611 $name == 'Normal' ? ' checked="checked"' : '',
612 $name
613 );
614 } ?>
615 </fieldset>
616 </td>
617 </tr>
618 </table>
619 </div>
620 <div class="bws_pro_version_tooltip">
621 <div class="bws_info">
622 <?php _e( 'Unlock premium options by upgrading to Pro version', 'google-captcha' ); ?>
623 </div>
624 <a class="bws_button" href="http://bestwebsoft.com/products/google-captcha/?k=b850d949ccc1239cab0da315c3c822ab&pn=109&v=<?php echo $gglcptch_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="Google Captcha Pro (reCAPTCHA)">
625 <?php _e( 'Learn More', 'google-captcha' ); ?>
626 </a>
627 <div class="clear"></div>
628 </div>
629 </div>
630 <?php } ?>
631 <p class="submit">
632 <input id="bws-submit-button" type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'google-captcha' ); ?>" name="gglcptch_save_changes" />
633 <input type="hidden" name="gglcptch_form_submit" value="submit" />
634 <?php wp_nonce_field( $plugin_basename, 'gglcptch_nonce_name' ); ?>
635 </p>
636 </form>
637 <?php bws_form_restore_default_settings( $plugin_basename );
638 }
639 } elseif ( 'go_pro' == $_GET['action'] ) {
640 bws_go_pro_tab_show( $bws_hide_premium_options_check, $gglcptch_plugin_info, $plugin_basename, 'google-captcha.php', 'google-captcha-pro.php', 'google-captcha-pro/google-captcha-pro.php', 'google-captcha', 'b850d949ccc1239cab0da315c3c822ab', '109', isset( $go_pro_result['pro_plugin_is_activated'] ) );
641 }
642 bws_plugin_reviews_block( $gglcptch_plugin_info['Name'], 'google-captcha' ); ?>
643 </div>
644 <?php }
645 }
646
647 /* Checking current user role */
648 if ( ! function_exists( 'gglcptch_check_role' ) ) {
649 function gglcptch_check_role() {
650 global $current_user, $gglcptch_options;
651
652 if ( ! is_user_logged_in() )
653 return false;
654
655 if ( ! empty( $current_user->roles[0] ) ) {
656 $role = $current_user->roles[0];
657 if ( empty( $gglcptch_options ) )
658 $gglcptch_options = get_option( 'gglcptch_options' );
659 return isset( $gglcptch_options[ $role ] ) && '1' == $gglcptch_options[ $role ] ? true : false;
660 } else
661 return false;
662 }
663 }
664
665 /* Display google captcha via shortcode */
666 if ( ! function_exists( 'gglcptch_display' ) ) {
667 function gglcptch_display( $content = false ) {
668 global $gglcptch_options, $gglcptch_count, $gglcptch_plugin_info;
669
670 if ( empty( $gglcptch_options ) )
671 $gglcptch_options = get_option( 'gglcptch_options' );
672
673 if ( ! $gglcptch_count )
674 $gglcptch_count = 1;
675
676 if ( ! gglcptch_get_allow_url_fopen() && isset( $gglcptch_options['recaptcha_version'] ) && $gglcptch_options['recaptcha_version'] == 'v2' ) {
677 $content .= '<div class="gglcptch allow_url_fopen_off"></div>';
678 $gglcptch_count++;
679 return $content;
680 }
681
682 $publickey = $gglcptch_options['public_key'];
683 $privatekey = $gglcptch_options['private_key'];
684
685 $content .= '<div class="gglcptch gglcptch_' . $gglcptch_options['recaptcha_version'] . '">';
686 if ( ! $privatekey || ! $publickey ) {
687 if ( current_user_can( 'manage_options' ) ) {
688 $content .= sprintf(
689 '<strong>%s <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s <a target="_blank" href="%s">%s</a>.</strong>',
690 __( 'To use Google Captcha you must get the keys from', 'google-captcha' ),
691 __ ( 'here', 'google-captcha' ),
692 __ ( 'and enter them on the', 'google-captcha' ),
693 admin_url( '/admin.php?page=google-captcha.php' ),
694 __( 'plugin setting page', 'google-captcha' )
695 );
696 }
697 $content .= '</div>';
698 $gglcptch_count++;
699 return $content;
700 }
701 if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) {
702 $content .= '<div id="gglcptch_recaptcha_' . $gglcptch_count . '" class="gglcptch_recaptcha"></div>
703 <noscript>
704 <div style="width: 302px;">
705 <div style="width: 302px; height: 422px; position: relative;">
706 <div style="width: 302px; height: 422px; position: absolute;">
707 <iframe src="https://www.google.com/recaptcha/api/fallback?k=' . $publickey . '" frameborder="0" scrolling="no" style="width: 302px; height:422px; border-style: none;"></iframe>
708 </div>
709 </div>
710 <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;">
711 <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>
712 </div>
713 </div>
714 </noscript>';
715 $api_url = "https://www.google.com/recaptcha/api.js";
716 } else {
717 require_once( 'lib/recaptchalib.php' );
718 $content .= '<div id="gglcptch_recaptcha_' . $gglcptch_count . '" class="gglcptch_recaptcha"></div>';
719 $content .= gglcptch_recaptcha_get_html( $publickey, null, is_ssl() );
720 $api_url = "//www.google.com/recaptcha/api/js/recaptcha_ajax.js";
721 }
722 $content .= '</div>';
723 $gglcptch_count++;
724
725 /* register reCAPTCHA script */
726 if ( ! wp_script_is( 'gglcptch_api', 'registered' ) ) {
727 wp_register_script( 'gglcptch_api', $api_url, false, $gglcptch_plugin_info["Version"], true );
728 add_action( 'wp_footer', 'gglcptch_add_scripts' );
729 if (
730 '1' == $gglcptch_options['login_form'] ||
731 '1' == $gglcptch_options['reset_pwd_form'] ||
732 '1' == $gglcptch_options['registration_form']
733 )
734 add_action( 'login_footer', 'gglcptch_add_scripts' );
735 }
736
737 return $content;
738 }
739 }
740
741 if ( ! function_exists( 'gglcptch_get_response' ) ) {
742 function gglcptch_get_response( $privatekey, $remote_ip ) {
743 $args = array(
744 'body' => array(
745 'secret' => $privatekey,
746 'response' => stripslashes( esc_html( $_POST["g-recaptcha-response"] ) ),
747 'remoteip' => $remote_ip,
748 ),
749 'sslverify' => false
750 );
751 $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $args );
752 return json_decode( wp_remote_retrieve_body( $resp ), true );
753 }
754 }
755
756 /* Check google captcha */
757 if ( ! function_exists( 'gglcptch_check' ) ) {
758 function gglcptch_check() {
759 global $gglcptch_options;
760
761 if ( ! gglcptch_get_allow_url_fopen() && isset( $gglcptch_options['recaptcha_version'] ) && $gglcptch_options['recaptcha_version'] == 'v2' ) {
762 return array(
763 'response' => false,
764 'reason' => 'ERROR_ALLOW_URL_FOPEN'
765 );
766 }
767
768 $publickey = $gglcptch_options['public_key'];
769 $privatekey = $gglcptch_options['private_key'];
770
771 if ( ! $privatekey || ! $publickey ) {
772 return array(
773 'response' => false,
774 'reason' => 'ERROR_NO_KEYS'
775 );
776 }
777
778 $gglcptch_remote_addr = filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP );
779
780 if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) {
781
782 if ( ! isset( $_POST["g-recaptcha-response"] ) ) {
783 return array(
784 'response' => false,
785 'reason' => 'RECAPTCHA_NO_RESPONSE'
786 );
787 } elseif ( empty( $_POST["g-recaptcha-response"] ) ) {
788 return array(
789 'response' => false,
790 'reason' => 'RECAPTCHA_EMPTY_RESPONSE'
791 );
792 }
793
794 $response = gglcptch_get_response( $privatekey, $gglcptch_remote_addr );
795
796 if ( isset( $response['success'] ) && !! $response['success'] ) {
797 return array(
798 'response' => true,
799 'reason' => ''
800 );
801 } else {
802 return array(
803 'response' => false,
804 'reason' => 'VERIFICATION_FAILED'
805 );
806 }
807 } else {
808 $gglcptch_recaptcha_challenge_field = $gglcptch_recaptcha_response_field = '';
809
810 if ( ! isset( $_POST['recaptcha_challenge_field'] ) && ! isset( $_POST['recaptcha_response_field'] ) ) {
811 return array(
812 'response' => false,
813 'reason' => 'RECAPTCHA_NO_RESPONSE'
814 );
815 } elseif ( ! empty( $_POST['recaptcha_challenge_field'] ) && empty( $_POST['recaptcha_response_field'] ) ) {
816 return array(
817 'response' => false,
818 'reason' => 'RECAPTCHA_EMPTY_RESPONSE'
819 );
820 } else {
821 $gglcptch_recaptcha_challenge_field = stripslashes( esc_html( $_POST['recaptcha_challenge_field'] ) );
822 $gglcptch_recaptcha_response_field = stripslashes( esc_html( $_POST['recaptcha_response_field'] ) );
823 }
824
825 require_once( 'lib/recaptchalib.php' );
826 $resp = gglcptch_recaptcha_check_answer( $privatekey, $gglcptch_remote_addr, $gglcptch_recaptcha_challenge_field, $gglcptch_recaptcha_response_field );
827 if ( ! $resp->is_valid ) {
828 return array(
829 'response' => false,
830 'reason' => 'VERIFICATION_FAILED'
831 );
832 } else {
833 return array(
834 'response' => true,
835 'reason' => ''
836 );
837 }
838 }
839 }
840 }
841
842 /* Add google captcha to the login form */
843 if ( ! function_exists( 'gglcptch_login_display' ) ) {
844 function gglcptch_login_display() {
845 global $gglcptch_options;
846 if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) {
847 $from_width = 302;
848 } else {
849 $from_width = 320;
850 if ( 'clean' == $gglcptch_options['theme'] )
851 $from_width = 450;
852 } ?>
853 <style type="text/css" media="screen">
854 #loginform,
855 #lostpasswordform,
856 #registerform {
857 width: <?php echo $from_width; ?>px !important;
858 }
859 #login_error,
860 .message {
861 width: <?php echo $from_width + 20; ?>px !important;
862 }
863 #loginform .gglcptch,
864 #lostpasswordform .gglcptch,
865 #registerform .gglcptch {
866 margin-bottom: 10px;
867 }
868 </style>
869 <?php echo gglcptch_display();
870 return true;
871 }
872 }
873
874 /* Check google captcha in login form */
875 if ( ! function_exists( 'gglcptch_login_check' ) ) {
876 function gglcptch_login_check( $user ) {
877
878 $result = gglcptch_check();
879
880 if ( ! $result['response'] ) {
881 if ( $result['reason'] == 'ERROR_ALLOW_URL_FOPEN' || $result['reason'] == 'ERROR_NO_KEYS' ) {
882 return $user;
883 }
884
885 $error_message = sprintf( '<strong>%s</strong>: %s', __( 'Error', 'google-captcha' ), __( 'You have entered an incorrect reCAPTCHA value.', 'google-captcha' ) );
886
887 if ( $result['reason'] == 'VERIFICATION_FAILED' ) {
888 wp_clear_auth_cookie();
889 return new WP_Error( 'gglcptch_error', $error_message );
890 }
891
892 if ( isset( $_REQUEST['log'] ) && isset( $_REQUEST['pwd'] ) ) {
893 return new WP_Error( 'gglcptch_error', $error_message );
894 } else {
895 return $user;
896 }
897 } else {
898 return $user;
899 }
900 }
901 }
902
903 /* Check google captcha in BWS Contact Form */
904 if ( ! function_exists( 'gglcptch_recaptcha_check' ) ) {
905 function gglcptch_recaptcha_check( $display_error = true ) {
906 /**
907 * this condition is necessary for compatibility
908 * with Contact Form ( Free and Pro ) by BestWebsoft plugins versions
909 * that use $_POST as parameter for hook ( old versions )
910 * apply_filters( 'cntctfrmpr_check_form', $_POST );
911 * @deprecated since 1.22
912 * @todo remove after some while
913 */
914 if ( is_array( $display_error ) )
915 $display_error = false;
916
917 $result = gglcptch_check();
918
919
920 if ( $result['response'] || $result['reason'] == 'ERROR_ALLOW_URL_FOPEN' || $result['reason'] == 'ERROR_NO_KEYS' )
921 return true;
922
923 return $display_error ? '<strong>' . __( 'Error', 'google-captcha' ) . '</strong>:&nbsp;' . __( 'You have entered an incorrect reCAPTCHA value', 'google-captcha' ) . '.' : false;
924
925 }
926 }
927
928 /* Check google captcha in lostpassword form */
929 if ( ! function_exists( 'gglcptch_lostpassword_check' ) ) {
930 function gglcptch_lostpassword_check( $allow ) {
931
932 $result = gglcptch_check();
933
934 if ( $result['response'] || $result['reason'] == 'ERROR_ALLOW_URL_FOPEN' || $result['reason'] == 'ERROR_NO_KEYS' )
935 return $allow;
936
937 if ( ! is_wp_error( $allow ) )
938 $allow = new WP_Error();
939
940 $allow->add( 'gglcptch_error', __( 'ERROR', 'google-captcha' ) . ':&nbsp;' . __( 'You have entered an incorrect reCAPTCHA value', 'google-captcha' ) . '.' );
941 return $allow;
942 }
943 }
944
945 /* Add google captcha to the multisite login form */
946 if ( ! function_exists( 'gglcptch_signup_display' ) ) {
947 function gglcptch_signup_display( $errors ) {
948 if ( $error_message = $errors->get_error_message( 'gglcptch_error' ) ) {
949 printf( '<p class="error gglcptch_error">%s</p>', $error_message );
950 }
951 echo gglcptch_display();
952 }
953 }
954
955 /* Check google captcha in multisite login form */
956 if ( ! function_exists( 'gglcptch_signup_check' ) ) {
957 function gglcptch_signup_check( $result ) {
958 global $current_user;
959
960 if ( is_admin() && ! empty( $current_user->data->ID ) )
961 return $result;
962
963 $check_result = gglcptch_check();
964
965 if ( $check_result['response'] || $check_result['reason'] == 'ERROR_ALLOW_URL_FOPEN' || $check_result['reason'] == 'ERROR_NO_KEYS' )
966 return $result;
967
968 $error = $result['errors'];
969 $error->add( 'gglcptch_error', __( 'ERROR', 'google-captcha' ) . ':&nbsp;' . __( 'You have entered an incorrect reCAPTCHA value', 'google-captcha' ) . '.' );
970 return $result;
971 }
972 }
973
974 /* Add google captcha to the comment form */
975 if ( ! function_exists( 'gglcptch_commentform_display' ) ) {
976 function gglcptch_commentform_display() {
977 if ( gglcptch_check_role() )
978 return;
979 echo gglcptch_display();
980 return true;
981 }
982 }
983
984 /* Check JS enabled for comment form */
985 if ( ! function_exists( 'gglcptch_commentform_check' ) ) {
986 function gglcptch_commentform_check() {
987 if ( gglcptch_check_role() )
988 return;
989
990 $result = gglcptch_check();
991
992 if ( $result['response'] || in_array( $result['reason'], array( 'ERROR_ALLOW_URL_FOPEN', 'ERROR_NO_KEYS' ) ) )
993 return;
994
995 wp_die( __( 'ERROR', 'google-captcha' ) . ':&nbsp;' . __( 'You have entered an incorrect reCAPTCHA value. Click the BACK button on your browser, and try again.', 'google-captcha' ) );
996 }
997 }
998
999 /* display google captcha in Contact form */
1000 if ( ! function_exists( 'gglcptch_cf_display' ) ) {
1001 function gglcptch_cf_display( $error_message, $content = "" ) {
1002 return $content . gglcptch_display();
1003 }
1004 }
1005
1006 /* Check Google Captcha in shortcode and contact form */
1007 if ( ! function_exists( 'gglcptch_captcha_check' ) ) {
1008 function gglcptch_captcha_check() {
1009 $result = gglcptch_check();
1010 echo $result['response'] ? "success" : "error";
1011 die();
1012 }
1013 }
1014
1015 if ( ! function_exists( 'gglcptch_action_links' ) ) {
1016 function gglcptch_action_links( $links, $file ) {
1017 if ( ! is_network_admin() ) {
1018 static $this_plugin;
1019 if ( ! $this_plugin )
1020 $this_plugin = plugin_basename(__FILE__);
1021
1022 if ( $file == $this_plugin ) {
1023 $settings_link = '<a href="admin.php?page=google-captcha.php">' . __( 'Settings', 'google-captcha' ) . '</a>';
1024 array_unshift( $links, $settings_link );
1025 }
1026 }
1027 return $links;
1028 }
1029 }
1030
1031 if ( ! function_exists( 'gglcptch_shortcode_button_content' ) ) {
1032 function gglcptch_shortcode_button_content( $content ) {
1033 global $wp_version; ?>
1034 <div id="gglcptch" style="display:none;">
1035 <input class="bws_default_shortcode" type="hidden" name="default" value="[bws_google_captcha]" />
1036 </div>
1037 <script type="text/javascript">
1038 function gglcptch_shortcode_init() {
1039 (function($) {
1040 var current_object = '<?php echo ( $wp_version < 3.9 ) ? "#TB_ajaxContent" : ".mce-reset" ?>';
1041 $( current_object + ' #bws_shortcode_display' ).bind( 'display_shortcode', function() {
1042 var shortcode = '[bws_google_captcha]';
1043 $( this ).text( shortcode );
1044 });
1045 })(jQuery);
1046 }
1047 </script>
1048 <?php }
1049 }
1050
1051 if ( ! function_exists( 'gglcptch_links' ) ) {
1052 function gglcptch_links( $links, $file ) {
1053 $base = plugin_basename( __FILE__ );
1054 if ( $file == $base ) {
1055 if ( ! is_network_admin() )
1056 $links[] = '<a href="admin.php?page=google-captcha.php">' . __( 'Settings', 'google-captcha' ) . '</a>';
1057 $links[] = '<a href="http://wordpress.org/plugins/google-captcha/faq/" target="_blank">' . __( 'FAQ', 'google-captcha' ) . '</a>';
1058 $links[] = '<a href="http://support.bestwebsoft.com">' . __( 'Support', 'google-captcha' ) . '</a>';
1059 }
1060 return $links;
1061 }
1062 }
1063
1064 if ( ! function_exists ( 'gglcptch_plugin_banner' ) ) {
1065 function gglcptch_plugin_banner() {
1066 global $hook_suffix, $gglcptch_plugin_info, $gglcptch_options;
1067 if ( 'plugins.php' == $hook_suffix ) {
1068 if ( empty( $gglcptch_options['public_key'] ) || empty( $gglcptch_options['private_key'] ) ) { ?>
1069 <div class="error">
1070 <p>
1071 <?php printf(
1072 '<strong>%s <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s <a target="_blank" href="%s">%s</a>.</strong>',
1073 __( 'To use Google Captcha you must get the keys from', 'google-captcha' ),
1074 __ ( 'here', 'google-captcha' ),
1075 __ ( 'and enter them on the', 'google-captcha' ),
1076 admin_url( '/admin.php?page=google-captcha.php' ),
1077 __( 'plugin setting page', 'google-captcha' )
1078 ); ?>
1079 </p>
1080 </div>
1081 <?php }
1082 if ( isset( $gglcptch_options['first_install'] ) && strtotime( '-1 week' ) > $gglcptch_options['first_install'] )
1083 bws_plugin_banner( $gglcptch_plugin_info, 'gglcptch', 'google-captcha', '676d9558f9786ab41d7de35335cf5c4d', '109', '//ps.w.org/google-captcha/assets/icon-128x128.png' );
1084
1085 bws_plugin_banner_to_settings( $gglcptch_plugin_info, 'gglcptch_options', 'google-captcha', 'admin.php?page=google-captcha.php' );
1086 }
1087 }
1088 }
1089
1090 /* add help tab */
1091 if ( ! function_exists( 'gglcptch_add_tabs' ) ) {
1092 function gglcptch_add_tabs() {
1093 $screen = get_current_screen();
1094 $args = array(
1095 'id' => 'gglcptch',
1096 'section' => '200538719'
1097 );
1098 bws_help_tab( $screen, $args );
1099 }
1100 }
1101
1102 if ( ! function_exists( 'gglcptch_delete_options' ) ) {
1103 function gglcptch_delete_options() {
1104 global $wpdb;
1105 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
1106 $old_blog = $wpdb->blogid;
1107 /* Get all blog ids */
1108 $blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" );
1109 foreach ( $blogids as $blog_id ) {
1110 switch_to_blog( $blog_id );
1111 delete_option( 'gglcptch_options' );
1112 }
1113 switch_to_blog( $old_blog );
1114 } else {
1115 delete_option( 'gglcptch_options' );
1116 }
1117 }
1118 }
1119
1120 add_action( 'admin_menu', 'gglcptch_admin_menu' );
1121
1122 add_action( 'init', 'gglcptch_init' );
1123 add_action( 'admin_init', 'gglcptch_admin_init' );
1124
1125 add_action( 'plugins_loaded', 'gglcptch_plugins_loaded' );
1126
1127 add_action( 'admin_enqueue_scripts', 'gglcptch_add_admin_script_styles' );
1128 add_action( 'wp_enqueue_scripts', 'gglcptch_add_styles' );
1129 add_filter( 'script_loader_tag', 'gglcptch_add_async_attribute', 10, 2 );
1130
1131 /* custom filter for bws button in tinyMCE */
1132 add_filter( 'bws_shortcode_button_content', 'gglcptch_shortcode_button_content' );
1133 add_shortcode( 'bws_google_captcha', 'gglcptch_display' );
1134 add_filter('widget_text', 'do_shortcode');
1135
1136 add_filter( 'plugin_action_links', 'gglcptch_action_links', 10, 2 );
1137 add_filter( 'plugin_row_meta', 'gglcptch_links', 10, 2 );
1138
1139 add_action( 'admin_notices', 'gglcptch_plugin_banner' );
1140
1141 add_action( 'wp_ajax_gglcptch_captcha_check', 'gglcptch_captcha_check' );
1142 add_action( 'wp_ajax_nopriv_gglcptch_captcha_check', 'gglcptch_captcha_check' );
1143
1144 register_uninstall_hook( __FILE__, 'gglcptch_delete_options' );