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