PluginProbe ʕ •ᴥ•ʔ
reCaptcha by BestWebSoft / 1.10
reCaptcha by BestWebSoft v1.10
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 11 years ago css 11 years ago images 11 years ago js 11 years ago languages 11 years ago lib 11 years ago google-captcha.php 11 years ago google_captcha_check.php 11 years ago readme.txt 11 years ago screenshot-1.png 11 years ago screenshot-2.png 11 years ago screenshot-3.png 11 years ago screenshot-4.png 11 years ago screenshot-5.png 11 years ago screenshot-6.png 11 years ago
google-captcha.php
567 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 Version: 1.10
8 Author URI: http://bestwebsoft.com/
9 License: GPLv3 or later
10 */
11
12 /* © Copyright 2014 BestWebSoft ( http://support.bestwebsoft.com )
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License, version 2, as
16 published by the Free Software Foundation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27
28 /* Add menu page */
29 if ( ! function_exists( 'google_capthca_admin_menu' ) ) {
30 function google_capthca_admin_menu() {
31 global $bstwbsftwppdtplgns_options, $bstwbsftwppdtplgns_added_menu;
32 $bws_menu_info = get_plugin_data( plugin_dir_path( __FILE__ ) . "bws_menu/bws_menu.php" );
33 $bws_menu_version = $bws_menu_info["Version"];
34 $base = plugin_basename( __FILE__ );
35
36 if ( ! isset( $bstwbsftwppdtplgns_options ) ) {
37 if ( is_multisite() ) {
38 if ( ! get_site_option( 'bstwbsftwppdtplgns_options' ) )
39 add_site_option( 'bstwbsftwppdtplgns_options', array(), '', 'yes' );
40 $bstwbsftwppdtplgns_options = get_site_option( 'bstwbsftwppdtplgns_options' );
41 } else {
42 if ( ! get_option( 'bstwbsftwppdtplgns_options' ) )
43 add_option( 'bstwbsftwppdtplgns_options', array(), '', 'yes' );
44 $bstwbsftwppdtplgns_options = get_option( 'bstwbsftwppdtplgns_options' );
45 }
46 }
47
48 if ( isset( $bstwbsftwppdtplgns_options['bws_menu_version'] ) ) {
49 $bstwbsftwppdtplgns_options['bws_menu']['version'][ $base ] = $bws_menu_version;
50 unset( $bstwbsftwppdtplgns_options['bws_menu_version'] );
51 if ( is_multisite() )
52 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options, '', 'yes' );
53 else
54 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options, '', 'yes' );
55 require_once( dirname( __FILE__ ) . '/bws_menu/bws_menu.php' );
56 } else if ( ! isset( $bstwbsftwppdtplgns_options['bws_menu']['version'][ $base ] ) || $bstwbsftwppdtplgns_options['bws_menu']['version'][ $base ] < $bws_menu_version ) {
57 $bstwbsftwppdtplgns_options['bws_menu']['version'][ $base ] = $bws_menu_version;
58 if ( is_multisite() )
59 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options, '', 'yes' );
60 else
61 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options, '', 'yes' );
62 require_once( dirname( __FILE__ ) . '/bws_menu/bws_menu.php' );
63 } else if ( ! isset( $bstwbsftwppdtplgns_added_menu ) ) {
64 $plugin_with_newer_menu = $base;
65 foreach ( $bstwbsftwppdtplgns_options['bws_menu']['version'] as $key => $value ) {
66 if ( $bws_menu_version < $value && is_plugin_active( $base ) ) {
67 $plugin_with_newer_menu = $key;
68 }
69 }
70 $plugin_with_newer_menu = explode( '/', $plugin_with_newer_menu );
71 $wp_content_dir = defined( 'WP_CONTENT_DIR' ) ? basename( WP_CONTENT_DIR ) : 'wp-content';
72 if ( file_exists( ABSPATH . $wp_content_dir . '/plugins/' . $plugin_with_newer_menu[0] . '/bws_menu/bws_menu.php' ) )
73 require_once( ABSPATH . $wp_content_dir . '/plugins/' . $plugin_with_newer_menu[0] . '/bws_menu/bws_menu.php' );
74 else
75 require_once( dirname( __FILE__ ) . '/bws_menu/bws_menu.php' );
76 $bstwbsftwppdtplgns_added_menu = true;
77 }
78
79 add_menu_page( 'BWS Plugins', 'BWS Plugins', 'manage_options', 'bws_plugins', 'bws_add_menu_render', plugins_url( "images/px.png", __FILE__ ), 1001 );
80 add_submenu_page( 'bws_plugins', __( 'Google Captcha Settings', 'google_captcha' ), __( 'Google Captcha', 'google_captcha' ), 'manage_options', 'google-captcha.php', 'gglcptch_settings_page' );
81 }
82 }
83
84 /* Function check if plugin is compatible with current WP version */
85 if ( ! function_exists ( 'gglcptch_version_check' ) ) {
86 function gglcptch_version_check() {
87 global $wp_version, $gglcptch_plugin_info;
88 $require_wp = "3.0"; /* Wordpress at least requires version */
89 $plugin = plugin_basename( __FILE__ );
90 if ( version_compare( $wp_version, $require_wp, "<" ) ) {
91 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
92 if ( is_plugin_active( $plugin ) ) {
93 deactivate_plugins( $plugin );
94 $admin_url = ( function_exists( 'get_admin_url' ) ) ? get_admin_url( null, 'plugins.php' ) : esc_url( '/wp-admin/plugins.php' );
95 if ( ! $gglcptch_plugin_info )
96 $gglcptch_plugin_info = get_plugin_data( __FILE__, false );
97 wp_die( "<strong>" . $gglcptch_plugin_info['Name'] . " </strong> " . __( 'requires', 'google_captcha' ) . " <strong>WordPress " . $require_wp . "</strong> " . __( 'or higher, that is why it has been deactivated! Please upgrade WordPress and try again.', 'google_captcha') . "<br /><br />" . __( 'Back to the WordPress', 'google_captcha') . " <a href='" . $admin_url . "'>" . __( 'Plugins page', 'google_captcha') . "</a>." );
98 }
99 }
100 }
101 }
102
103 if ( ! function_exists( 'gglcptch_init' ) ) {
104 function gglcptch_init() {
105 global $gglcptch_options;
106
107 load_plugin_textdomain( 'google_captcha', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
108
109 /* Check version on WordPress */
110 gglcptch_version_check();
111
112 /* Get options from the database */
113 $gglcptch_options = get_option( 'gglcptch_options' );
114
115 /* Add hooks */
116 if ( '1' == $gglcptch_options['login_form'] ) {
117 add_action( 'login_form', 'gglcptch_login_display' );
118 add_filter( 'login_redirect', 'gglcptch_login_check', 10, 3 );
119 }
120
121 if ( '1' == $gglcptch_options['comments_form'] ) {
122 add_action( 'comment_form_after_fields', 'gglcptch_commentform_display' );
123 add_action( 'comment_form_logged_in_after', 'gglcptch_commentform_display' );
124 }
125
126 if ( '1' == $gglcptch_options['reset_pwd_form'] ) {
127 add_action( 'lostpassword_form', 'gglcptch_login_display' );
128 add_action( 'lostpassword_post', 'gglcptch_lostpassword_check' );
129 }
130
131 if ( '1' == $gglcptch_options['registration_form'] ) {
132 add_action( 'register_form', 'gglcptch_login_display' );
133 add_action( 'register_post', 'gglcptch_lostpassword_check' );
134 }
135 if ( '1' == $gglcptch_options['contact_form'] ) {
136 add_filter( 'cntctfrm_display_captcha', 'gglcptch_display' );
137 add_filter( 'cntctfrmpr_display_captcha', 'gglcptch_display' );
138 } elseif ( '0' == $gglcptch_options['contact_form'] ) {
139 remove_filter( 'cntctfrm_display_captcha', 'gglcptch_display' );
140 remove_filter( 'cntctfrmpr_display_captcha', 'gglcptch_display' );
141 }
142 }
143 }
144
145 if ( ! function_exists( 'gglcptch_admin_init' ) ) {
146 function gglcptch_admin_init() {
147 global $bws_plugin_info, $gglcptch_plugin_info;
148
149 if ( ! $gglcptch_plugin_info )
150 $gglcptch_plugin_info = get_plugin_data( __FILE__, false );
151
152 if ( ! isset( $bws_plugin_info ) || empty( $bws_plugin_info ) )
153 $bws_plugin_info = array( 'id' => '109', 'version' => $gglcptch_plugin_info["Version"] );
154
155 /* Call register settings function */
156 if ( isset( $_GET['page'] ) && "google-captcha.php" == $_GET['page'] )
157 register_gglcptch_settings();
158 }
159 }
160
161 /* Add google captcha styles */
162 if ( ! function_exists( 'gglcptch_add_style' ) ) {
163 function gglcptch_add_style() {
164 if ( isset( $_REQUEST['page'] ) && 'google-captcha.php' == $_REQUEST['page'] )
165 wp_enqueue_style( 'gglcptch_stylesheet', plugins_url( 'css/style.css', __FILE__ ) );
166 }
167 }
168
169 /* Add google captcha scripts */
170 if ( ! function_exists( 'gglcptch_add_script' ) ) {
171 function gglcptch_add_script() {
172 wp_enqueue_script( 'gglcptch_script', plugins_url( 'js/script.js', __FILE__ ), array( 'jquery' ) );
173 }
174 }
175 /* Google catpcha settings */
176 if ( ! function_exists( 'register_gglcptch_settings' ) ) {
177 function register_gglcptch_settings() {
178 global $gglcptch_options, $bws_plugin_info, $gglcptch_plugin_info;
179
180 $gglcptch_default_options = array(
181 'public_key' => '',
182 'private_key' => '',
183 'login_form' => '1',
184 'registration_form' => '1',
185 'reset_pwd_form' => '1',
186 'comments_form' => '1',
187 'contact_form' => '0',
188 'theme' => 'red',
189 'plugin_option_version' => $gglcptch_plugin_info["Version"]
190 );
191
192 foreach ( get_editable_roles() as $role => $fields ) {
193 $gglcptch_default_options[ $role ] = '0';
194 }
195
196 /* Install the option defaults */
197 if ( ! get_option( 'gglcptch_options' ) )
198 add_option( 'gglcptch_options', $gglcptch_default_options, '', 'yes' );
199 /* Get options from the database */
200 $gglcptch_options = get_option( 'gglcptch_options' );
201
202 /* Array merge incase this version has added new options */
203 if ( ! isset( $gglcptch_options['plugin_option_version'] ) || $gglcptch_options['plugin_option_version'] != $gglcptch_plugin_info["Version"] ) {
204 $gglcptch_options = array_merge( $gglcptch_default_options, $gglcptch_options );
205 $gglcptch_options['plugin_option_version'] = $gglcptch_plugin_info["Version"];
206 update_option( 'gglcptch_options', $gglcptch_options );
207 }
208 }
209 }
210
211 /* Display settings page */
212 if ( ! function_exists( 'gglcptch_settings_page' ) ) {
213 function gglcptch_settings_page() {
214 global $gglcptch_options, $gglcptch_plugin_info, $wp_version;
215
216 /* Private and public keys */
217 $gglcptch_keys = array(
218 'public' => array(
219 'display_name' => __( 'Site key', 'google_captcha' ),
220 'form_name' => 'gglcptch_public_key',
221 'error_msg' => '',
222 ),
223 'private' => array(
224 'display_name' => __( 'Secret Key', 'google_captcha' ),
225 'form_name' => 'gglcptch_private_key',
226 'error_msg' => '',
227 ),
228 );
229
230 /* Checked forms */
231 $gglcptch_forms = array(
232 array( 'login_form', __( 'Login form', 'google_captcha' ) ),
233 array( 'registration_form', __( 'Registration form', 'google_captcha' ) ),
234 array( 'reset_pwd_form', __( 'Reset password form', 'google_captcha' ) ),
235 array( 'comments_form', __( 'Comments form', 'google_captcha' ) ),
236 );
237
238 /* Google captcha themes */
239 $gglcptch_themes = array(
240 array( 'red', 'Red' ),
241 array( 'white', 'White' ),
242 array( 'blackglass', 'Blackglass' ),
243 array( 'clean', 'Clean' ),
244 );
245
246 $error = '';
247 /* Save data for settings page */
248 if ( isset( $_POST['gglcptch_save_changes'] ) && check_admin_referer( plugin_basename( __FILE__ ), 'gglcptch_nonce_name' ) ) {
249 if ( ! $_POST['gglcptch_public_key'] || '' == $_POST['gglcptch_public_key'] ) {
250 $gglcptch_keys['public']['error_msg'] = __( 'Enter site key', 'google_captcha' );
251 $error = __( "WARNING: The captcha will not display while you don't fill key fields.", 'google_captcha' );
252 } else
253 $gglcptch_keys['public']['error_msg'] = '';
254
255 if ( ! $_POST['gglcptch_private_key'] || '' == $_POST['gglcptch_private_key'] ) {
256 $gglcptch_keys['private']['error_msg'] = __( 'Enter secret key', 'google_captcha' );
257 $error = __( "WARNING: The captcha will not display while you don't fill key fields.", 'google_captcha' );
258 } else
259 $gglcptch_keys['private']['error_msg'] = '';
260
261 $gglcptch_options['public_key'] = trim( stripslashes( esc_html( $_POST['gglcptch_public_key'] ) ) );
262 $gglcptch_options['private_key'] = trim( stripslashes( esc_html( $_POST['gglcptch_private_key'] ) ) );
263 $gglcptch_options['login_form'] = isset( $_POST['gglcptch_login_form'] ) ? 1 : 0;
264 $gglcptch_options['registration_form'] = isset( $_POST['gglcptch_registration_form'] ) ? 1 : 0;
265 $gglcptch_options['reset_pwd_form'] = isset( $_POST['gglcptch_reset_pwd_form'] ) ? 1 : 0;
266 $gglcptch_options['comments_form'] = isset( $_POST['gglcptch_comments_form'] ) ? 1 : 0;
267 $gglcptch_options['contact_form'] = isset( $_POST['gglcptch_contact_form'] ) ? 1 : 0;
268 $gglcptch_options['theme'] = $_POST['gglcptch_theme'];
269
270 foreach ( get_editable_roles() as $role => $fields ) {
271 $gglcptch_options[ $role ] = isset( $_POST[ 'gglcptch_' . $role ] ) ? 1 : 0;
272 }
273
274 update_option( 'gglcptch_options', $gglcptch_options );
275 } ?>
276 <div class="wrap">
277 <h2><?php _e( 'Google Captcha Settings', 'google_captcha' ); ?></h2>
278 <h2 class="nav-tab-wrapper">
279 <a class="nav-tab nav-tab-active" href="admin.php?page=google-captcha.php"><?php _e( 'Settings', 'google_captcha' ); ?></a>
280 <a class="nav-tab" href="http://bestwebsoft.com/products/google-captcha/faq" target="_blank"><?php _e( 'FAQ', 'google_captcha' ); ?></a>
281 </h2>
282 <div class="updated fade" <?php if ( ! isset( $_POST['gglcptch_save_changes'] ) || "" != $error ) echo 'style="display:none"'; ?>><p><strong><?php _e( 'Settings saved', 'google_captcha' ); ?></strong></p></div>
283 <div class="error" <?php if ( "" == $error ) echo 'style="display:none"'; ?>><p><strong><?php echo $error; ?></strong></p></div>
284 <p><?php _e( 'If you would like to add the Google Captcha to your own form, just copy and paste this shortcode to your post or page:', 'google_captcha' ); echo ' [bws_google_captcha]'; ?></p>
285 <form method="post" action="admin.php?page=google-captcha.php">
286 <h3><?php _e( 'Authentication', 'google_captcha' ); ?></h3>
287 <p><?php printf( __( 'Before you are able to do something, you must to register %s here %s', 'google_captcha' ), '<a target="_blank" href="https://www.google.com/recaptcha/admin#list">','</a>.' ); ?></p>
288 <p><?php _e( 'Enter site key and secret key, that you get after registration.', 'google_captcha' ); ?></p>
289 <table id="gglcptch-keys" class="form-table">
290 <?php foreach ( $gglcptch_keys as $key => $fields ) : ?>
291 <tr valign="top">
292 <th scope="row"><?php echo $fields['display_name']; ?></th>
293 <td>
294 <input type="text" name="<?php echo $fields['form_name']; ?>" value="<?php echo $gglcptch_options[ $key . '_key' ] ?>" />
295 <label class="gglcptch_error_msg"><?php echo $fields['error_msg']; ?></label>
296 </td>
297 </tr>
298 <?php endforeach; ?>
299 </table>
300 <h3><?php _e( 'Options', 'google_captcha' ); ?></h3>
301 <table class="form-table">
302 <tr valign="top">
303 <th scope="row"><?php _e( 'Enable Google Captcha for:', 'google_captcha' ); ?></th>
304 <td>
305 <?php foreach ( $gglcptch_forms as $form ) : ?>
306 <label><input type="checkbox" name="<?php echo 'gglcptch_' . $form[0]; ?>" value=<?php echo $form[0]; if ( '1' == $gglcptch_options[ $form[0] ] ) echo ' checked'; ?>><?php echo $form[1]; ?></label><br />
307 <?php endforeach;
308 $gglcptch_all_plugins = get_plugins();
309 $gglcptch_cntctfrm_installed = ( isset( $gglcptch_all_plugins['contact-form-plugin/contact_form.php'] ) || isset( $gglcptch_all_plugins['contact-form-pro/contact_form_pro.php'] ) ) ? true : false;
310 $gglcptch_active_plugins = get_option( 'active_plugins' );
311 if ( is_multisite() ) {
312 $gglcptch_active_network_plugins = array_flip( get_site_option('active_sitewide_plugins') );
313 $gglcptch_active_plugins = array_unique( array_merge( $gglcptch_active_plugins, $gglcptch_active_network_plugins ) );
314 }
315 $gglcptch_cntctfrm_activated = ( in_array( 'contact-form-plugin/contact_form.php', $gglcptch_active_plugins ) || in_array( 'contact-form-pro/contact_form_pro.php', $gglcptch_active_plugins ) ) ? true : false;
316 if ( $gglcptch_cntctfrm_installed ) :
317 if ( $gglcptch_cntctfrm_activated ) : ?>
318 <label><input type="checkbox" name="gglcptch_contact_form" value="contact_form"<?php if ( '1' == $gglcptch_options['contact_form'] ) echo ' checked'; ?>><?php _e( 'Contact form', 'google_captcha' ); ?></label>
319 <span style="color: #888888;font-size: 10px;">(<?php _e( 'powered by', 'google_captcha' ); ?> <a href="http://bestwebsoft.com/products/">bestwebsoft.com</a>)</span><br />
320 <?php else : ?>
321 <label><input type="checkbox" disabled name="gglcptch_contact_form" value="contact_form"<?php if ( '1' == $gglcptch_options['contact_form'] ) echo ' checked'; ?>><?php _e( 'Contact form', 'google_captcha' ); ?></label>
322 <span style="color: #888888;font-size: 10px;">(<?php _e( 'powered by', 'google_captcha' ); ?> <a href="http://bestwebsoft.com/products/">bestwebsoft.com</a>) <a href="<?php echo bloginfo("url"); ?>/wp-admin/plugins.php"><?php _e( 'Activate contact form', 'google_captcha' ); ?></a></span><br />
323 <?php endif;
324 else : ?>
325 <label><input type="checkbox" disabled name="gglcptch_contact_form" value="contact_form"<?php if ( '1' == $gglcptch_options['contact_form'] ) echo ' checked'; ?>><?php _e( 'Contact form', 'google_captcha' ); ?></label>
326 <span style="color: #888888;font-size: 10px;">(<?php _e( 'powered by', 'google_captcha' ); ?> <a href="http://bestwebsoft.com/products/">bestwebsoft.com</a>) <a href="http://bestwebsoft.com/products/contact-form/?k=d70b58e1739ab4857d675fed2213cedc&pn=75&v=<?php echo $gglcptch_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>"><?php _e( 'Download contact form', 'google_captcha' ); ?></a></span><br />
327 <?php endif; ?>
328 </td>
329 </tr>
330 <tr valign="top">
331 <th scope="row"><?php _e( 'Hide captcha for:', 'google_captcha' ); ?></th>
332 <td>
333 <?php foreach ( get_editable_roles() as $role => $fields) : ?>
334 <label><input type="checkbox" name="<?php echo 'gglcptch_' . $role; ?>" value=<?php echo $role; if ( '1' == $gglcptch_options[ $role ] ) echo ' checked'; ?>><?php echo $fields['name']; ?></label><br/>
335 <?php endforeach; ?>
336 </td>
337 </tr>
338 <tr valign="top">
339 <th scope="row"><?php _e( 'Theme:', 'google_captcha' ); ?></th>
340 <td>
341 <select name="gglcptch_theme">
342 <?php foreach ( $gglcptch_themes as $theme ) : ?>
343 <option value=<?php echo $theme[0]; if ( $theme[0] == $gglcptch_options['theme'] ) echo ' selected'; ?> ><?php echo $theme[1]; ?></option>
344 <?php endforeach; ?>
345 </select>
346 </td>
347 </tr>
348 </table>
349 <p class="submit">
350 <input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'google_captcha' ); ?>" name="gglcptch_save_changes" />
351 </p>
352 <?php wp_nonce_field( plugin_basename( __FILE__ ), 'gglcptch_nonce_name' ); ?>
353 </form>
354 <div class="bws-plugin-reviews">
355 <div class="bws-plugin-reviews-rate">
356 <?php _e( 'If you enjoy our plugin, please give it 5 stars on WordPress', 'google_captcha' ); ?>:
357 <a href="http://wordpress.org/support/view/plugin-reviews/google-captcha" target="_blank" title="Google Captcha reviews"><?php _e( 'Rate the plugin', 'google_captcha' ); ?></a>
358 </div>
359 <div class="bws-plugin-reviews-support">
360 <?php _e( 'If there is something wrong about it, please contact us', 'google_captcha' ); ?>:
361 <a href="http://support.bestwebsoft.com">http://support.bestwebsoft.com</a>
362 </div>
363 </div>
364 </div>
365 <?php }
366 }
367
368 /* Checking current user role */
369 if ( ! function_exists( 'gglcptch_check_role' ) ) {
370 function gglcptch_check_role() {
371 global $current_user, $gglcptch_options;
372 if ( ! is_user_logged_in() )
373 return false;
374 $role = $current_user->roles[0];
375 if ( '1' == $gglcptch_options[ $role ] )
376 return true;
377 else
378 return false;
379 }
380 }
381
382 /* Display google captcha via shortcode */
383 if ( ! function_exists( 'gglcptch_display' ) ) {
384 function gglcptch_display( $content = false ) {
385 if ( gglcptch_check_role() )
386 return;
387 global $gglcptch_options, $gglcptch_count;
388 if ( empty( $gglcptch_count ) ) {
389 $gglcptch_count = 1;
390 }
391 if ( $gglcptch_count > 1 ) {
392 return $content;
393 }
394 require_once( 'lib/recaptchalib.php' );
395 $publickey = $gglcptch_options['public_key'];
396 $privatekey = $gglcptch_options['private_key'];
397 $content .= '<div class="gglcptch">';
398 if ( ! $privatekey || ! $publickey ) {
399 if ( current_user_can( 'manage_options' ) ) {
400 $content .= sprintf(
401 '<strong>%s <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s <a target="_blank" href="%s">%s</a>.</strong>',
402 __( 'To use Google Captcha you must get the keys from', 'google_captcha' ),
403 __ ( 'here', 'google_captcha' ),
404 __ ( 'and enter them on the', 'google_captcha' ),
405 admin_url( '/admin.php?page=google-captcha.php' ),
406 __( 'plugin setting page', 'google_captcha' )
407 );
408 }
409 $content .= '</div>';
410 $gglcptch_count++;
411 return $content;
412 }
413 $content .= sprintf(
414 '<style type="text/css" media="screen">
415 #recaptcha_response_field {
416 max-height: 35px;
417 }
418 #gglcptch_error {
419 color: #F00;
420 }
421 </style>
422 <script type="text/javascript">
423 var RecaptchaOptions = { theme : "%s" },
424 gglcptch_path = "%s",
425 gglcptch_error_msg = "%s";
426 </script>',
427 $gglcptch_options['theme'],
428 plugins_url( 'google_captcha_check.php', __FILE__ ),
429 __( 'Error: You have entered an incorrect CAPTCHA value.', 'google_captcha' )
430 );
431 if ( is_ssl() )
432 $content .= recaptcha_get_html( $publickey, '', true );
433 else
434 $content .= recaptcha_get_html( $publickey );
435 $content .= '</div>';
436 $gglcptch_count++;
437 return $content;
438 }
439 }
440
441 /* Add google captcha to the login form */
442 if ( ! function_exists( 'gglcptch_login_display' ) ) {
443 function gglcptch_login_display() {
444 global $gglcptch_options;
445 $from_width = 320;
446 if ( 'clean' == $gglcptch_options['theme'] )
447 $from_width = 450; ?>
448 <style type="text/css" media="screen">
449 #loginform,
450 #lostpasswordform,
451 #registerform {
452 width: <?php echo $from_width; ?>px !important;
453 }
454 .message {
455 width: <?php echo $from_width + 20; ?>px !important;
456 }
457 </style>
458 <?php echo gglcptch_display();
459 return true;
460 }
461 }
462
463 /* Check google captcha in login form */
464 if ( ! function_exists( 'gglcptch_login_check' ) ) {
465 function gglcptch_login_check( $redirect_to, $request, $user ) {
466 if ( isset( $_POST['wp-submit'] ) ) {
467 global $gglcptch_options;
468 require_once( 'lib/recaptchalib.php' );
469 $publickey = $gglcptch_options['public_key'];
470 $privatekey = $gglcptch_options['private_key'];
471
472 if ( ! $privatekey || ! $publickey ) {
473 return $redirect_to;
474 }
475
476 $resp = recaptcha_check_answer( $privatekey, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'] );
477
478 if ( ! $resp->is_valid ) {
479 wp_clear_auth_cookie();
480 wp_die( __( 'Error: You have entered an incorrect CAPTCHA value. Click the BACK button on your browser, and try again.', 'google_captcha' ) );
481 } else {
482 return $redirect_to;
483 }
484 } else {
485 return $redirect_to;
486 }
487 }
488 }
489
490 /* Add google captcha to the comment form */
491 if ( ! function_exists( 'gglcptch_commentform_display' ) ) {
492 function gglcptch_commentform_display() {
493 if ( gglcptch_check_role() )
494 return;
495 echo gglcptch_display();
496 return true;
497 }
498 }
499
500 /* Check google captcha in lostpassword form */
501 if ( ! function_exists( 'gglcptch_lostpassword_check' ) ) {
502 function gglcptch_lostpassword_check() {
503 global $gglcptch_options;
504 require_once( 'lib/recaptchalib.php' );
505 $publickey = $gglcptch_options['public_key'];
506 $privatekey = $gglcptch_options['private_key'];
507
508 if ( ! $privatekey || ! $publickey )
509 return;
510
511 $resp = recaptcha_check_answer( $privatekey,
512 $_SERVER['REMOTE_ADDR'],
513 $_POST['recaptcha_challenge_field'],
514 $_POST['recaptcha_response_field'] );
515 if ( ! $resp->is_valid ) {
516 wp_die( __( 'Error: You have entered an incorrect CAPTCHA value. Click the BACK button on your browser, and try again.', 'google_captcha' ) );
517 } else
518 return;
519 }
520 }
521
522 if ( ! function_exists( 'gglcptch_action_links' ) ) {
523 function gglcptch_action_links( $links, $file ) {
524 /* Static so we don't call plugin_basename on every plugin row. */
525 static $this_plugin;
526 if ( ! $this_plugin )
527 $this_plugin = plugin_basename(__FILE__);
528
529 if ( $file == $this_plugin ){
530 $settings_link = '<a href="admin.php?page=google-captcha.php">' . __( 'Settings', 'google_captcha' ) . '</a>';
531 array_unshift( $links, $settings_link );
532 }
533 return $links;
534 }
535 }
536
537 if ( ! function_exists( 'gglcptch_links' ) ) {
538 function gglcptch_links( $links, $file ) {
539 $base = plugin_basename( __FILE__ );
540 if ( $file == $base ) {
541 $links[] = '<a href="admin.php?page=google_captcha.php">' . __( 'Settings', 'google_captcha' ) . '</a>';
542 $links[] = '<a href="http://wordpress.org/plugins/google-captcha/faq/" target="_blank">' . __( 'FAQ', 'google_captcha' ) . '</a>';
543 $links[] = '<a href="http://support.bestwebsoft.com">' . __( 'Support', 'google_captcha' ) . '</a>';
544 }
545 return $links;
546 }
547 }
548
549 if ( ! function_exists( 'gglcptch_delete_options' ) ) {
550 function gglcptch_delete_options() {
551 delete_option( 'gglcptch_options' );
552 }
553 }
554
555 add_action( 'admin_menu', 'google_capthca_admin_menu' );
556 add_action( 'init', 'gglcptch_init' );
557 add_action( 'admin_init', 'gglcptch_admin_init' );
558 add_action( 'admin_enqueue_scripts', 'gglcptch_add_style' );
559 add_action( 'wp_enqueue_scripts', 'gglcptch_add_script' );
560
561 add_shortcode( 'bws_google_captcha', 'gglcptch_display' );
562
563 add_filter( 'plugin_action_links', 'gglcptch_action_links', 10, 2 );
564 add_filter( 'plugin_row_meta', 'gglcptch_links', 10, 2 );
565
566 register_uninstall_hook( __FILE__, 'gglcptch_delete_options' );
567 ?>