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