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