Changeset 1137085
- Timestamp:
- 04/17/2015 12:36:27 PM (11 years ago)
- Location:
- buddypress-nocaptcha-register-box/trunk
- Files:
-
- 2 edited
-
mmbp-nocaptcha.php (modified) (4 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
buddypress-nocaptcha-register-box/trunk/mmbp-nocaptcha.php
r1136908 r1137085 4 4 Plugin URI: http://www.functionsphp.com/recaptcha 5 5 Description: This super-lightweight plugin adds a Google's No Captcha human friendly reCAPTCHA box to the BuddyPress registration form. 6 It should help keep your community free from spammers and also hopefully not be too much of a inconvenience for your site's users. 7 Based on Buddypress ReCaptacha by Hardeep Asrani, modified for latest reCaptcha API. 8 Version: 1.0 6 It should help keep your community free from spambots and also hopefully not be too much of a inconvenience for your sites genuine users. 7 You can set a dark or light theme. The type of captcha can be set to image or audio and there are over 30 languages available for the NoCaptcha box. Or, set it to auto, based on the users browser language. 8 (Plugin code based on Buddypress ReCaptacha by Hardeep Asrani, modified for latest reCaptcha API.) 9 Version: 1.1 9 10 Author: Neil Foster 10 11 Author URI: http://www.mokummusic.com … … 18 19 function enqueue_mokum_nocaptcha_scripts() { 19 20 20 wp_register_script('mokumnocaptchaScript', 'https://www.google.com/recaptcha/api.js', '','', true); 21 if (function_exists('bp_is_register_page') && bp_is_register_page()) wp_enqueue_script('mokumnocaptchaScript'); 21 if (get_option('mmbpcapt_lang') != '' && get_option('mmbpcapt_lang') !== 'xx') $lang = '&hl='.get_option('mmbpcapt_lang'); 22 23 wp_register_script('googleRecaptchaScript', 'https://www.google.com/recaptcha/api.js?onload=onloadCaptchaCallback&render=explicit'.$lang, '','', true); 24 if (function_exists('bp_is_register_page') && bp_is_register_page()) wp_enqueue_script('googleRecaptchaScript'); 22 25 } 23 26 add_action( 'wp_enqueue_scripts', 'enqueue_mokum_nocaptcha_scripts'); 27 28 29 // Make recaptcha script load asynchronously 30 add_filter( 'script_loader_tag', function ( $tag, $handle ) { 31 if ( 'googleRecaptchaScript' !== $handle ) return $tag; 32 return str_replace( ' src', ' async="async" defer="defer" src', $tag ); 33 }, 10, 2 ); 34 24 35 25 36 // ********** ADMIN SETTINGS FUNCTIONS ************** 26 37 27 38 function mmbpcapt_init() { 28 add_option( 'mmbpcapt_public'); 29 add_option( 'mmbpcapt_private'); 30 add_option( 'mmbpcapt_theme', 'light'); 39 register_setting( 'mmbpcapt', 'mmbpcapt_public' ); 40 register_setting( 'mmbpcapt', 'mmbpcapt_private' ); 41 register_setting( 'mmbpcapt', 'mmbpcapt_theme' ); 42 register_setting( 'mmbpcapt', 'mmbpcapt_type' ); 43 register_setting( 'mmbpcapt', 'mmbpcapt_lang' ); 44 register_setting( 'mmbpcapt', 'mmbpcapt_style' ); 45 add_option( 'mmbpcapt_public'); 46 add_option( 'mmbpcapt_private'); 47 add_option( 'mmbpcapt_theme', 'light'); 48 add_option( 'mmbpcapt_type', 'image'); 49 add_option( 'mmbpcapt_lang', 'xx'); 31 50 add_option( 'mmbpcapt_style', 'clear:both; float:right; margin-top:30px;'); 32 register_setting( 'mmbpcapt', 'mmbpcapt_public' );33 register_setting( 'mmbpcapt', 'mmbpcapt_private' );34 register_setting( 'mmbpcapt', 'mmbpcapt_theme' );35 register_setting( 'mmbpcapt', 'mmbpcapt_style' );36 51 } 37 52 add_action('admin_init', 'mmbpcapt_init' ); 38 53 39 54 function mmbpcapt_register_options_page() { 40 55 add_options_page('BuddyPress noCaptcha', 'BuddyPress noCaptcha', 'manage_options', 'bp-captcha', 'mmbpcapt_options_page'); 41 56 } 42 57 add_action('admin_menu', 'mmbpcapt_register_options_page'); 43 58 44 59 function mmbpcapt_options_page() { 45 ?> 46 <div class="wrap"> 47 <?php screen_icon(); ?> 48 <h2>BuddyPress No Captcha reCaptcha</h2> 49 <form method="post" action="options.php"> 50 <?php settings_fields( 'mmbpcapt' ); ?> 51 <p>If you don't already have your Google reCaptcha API private and public keys, click <a href="https://www.google.com/recaptcha/admin" target="_blank">here</a> to get them.</p> 52 <table class="form-table"> 53 <tr valign="top"> 54 <th scope="row"><label for="mmbpcapt_public">reCAPTCHA Site Key:</label></th> 55 <td><input type="text" id="mmbpcapt_public" name="mmbpcapt_public" value="<?php echo get_option('mmbpcapt_public'); ?>" /></td> 56 </tr> 57 <tr valign="top"> 58 <th scope="row"><label for="mmbpcapt_private">reCAPTCHA Secret Key:</label></th> 59 <td><input type="text" id="mmbpcapt_private" name="mmbpcapt_private" value="<?php echo get_option('mmbpcapt_private'); ?>" /></td> 60 </tr> 61 <tr valign="top"> 62 <th scope="row"><label for="mmbpcapt_theme">Theme:</label></th> 63 <td><select id="mmbpcapt_theme" name="mmbpcapt_theme" value=" <?php 64 echo get_option('mmbpcapt_theme'); ?>"> 65 <option value="light" <?php 66 if (get_option('mmbpcapt_theme') == light) echo 'selected="selected"'; ?>>Light</option> 67 <option value="dark" <?php 68 if (get_option('mmbpcapt_theme') == dark) echo 'selected="selected"'; ?>>Dark</option> 69 </select></td> 70 </tr> 71 <tr valign="top"> 72 <th scope="row"><label for="mmbpcapt_style">reCAPTCHA container CSS style:</label></th> 73 <td><input type="text" id="mmbpcapt_style" name="mmbpcapt_style" value="<?php echo get_option('mmbpcapt_style'); ?>" /></td> 74 </tr> 75 </table> 76 <?php submit_button(); ?> 77 </form> 78 <span>More Wordpress fun at <a target="_blank" href="http://www.functionsphp.com/">functionsphp.com</a></span> 79 </div> 80 <?php 60 include 'admin-settings-template.php'; 81 61 } 82 62 83 63 // ********** FRONT END ************** 84 64 85 $public_key = get_option('mmbpcapt_public');86 $private_key = get_option('mmbpcapt_private');87 $theme = get_option('mmbpcapt_theme');88 $style = get_option('mmbpcapt_style');89 90 65 add_action( 'bp_before_registration_submit_buttons', 'bp_add_code' ); 91 66 add_action( 'bp_signup_validate', 'bp_validate' ); 92 67 93 68 function bp_add_code() { 94 global $bp, $theme, $style, $public_key; 95 $html = '<div class="register-section" id="security-section" style="'.$style.'">'; 96 $html .= '<div class="editfield">'; 69 global $bp; 70 ?> 97 71 98 if (!empty($bp->signup->errors['recaptcha_response_field'])) { 99 $html .= '<div class="error">'; 100 $html .= $bp->signup->errors['recaptcha_response_field']; 101 $html .= '</div>'; 102 } 103 $html .= '<div class="g-recaptcha" data-sitekey="'.$public_key.'" data-theme="'.$theme.'"></div>'; 104 if ($public_key == null || $public_key == '') $html .= "Enter your reCAPTCHA API keys in Wordpress admin settings!"; 105 106 $html .= '</div></div>'; 107 echo $html; 72 <div class="register-section" id="security-section" style="<?php echo get_option('mmbpcapt_style'); ?>"> 73 <div class="editfield"> 74 <?php if (!empty($bp->signup->errors['recaptcha_response_field'])) : ?> 75 <div class="error"><?php echo $bp->signup->errors['recaptcha_response_field']; ?></div> 76 <?php endif; ?> 77 78 <div id="mm-nocaptcha"></div> 79 80 <?php if (get_option('mmbpcapt_public') == null || get_option('mmbpcapt_public') == '') echo "Enter your reCAPTCHA API keys in Wordpress admin settings!"; ?> 81 82 </div> 83 </div> 84 <script type="text/javascript"> 85 var onloadCaptchaCallback = function() { 86 grecaptcha.render('mm-nocaptcha', { 87 'sitekey' : '<?php echo get_option('mmbpcapt_public'); ?>', 88 'theme' : '<?php echo get_option('mmbpcapt_theme'); ?>', 89 'type' : '<?php echo get_option('mmbpcapt_type'); ?>' 90 }); 91 }; 92 </script> 93 <?php 108 94 } 109 95 110 96 function bp_validate() { 111 global $bp , $private_key;97 global $bp; 112 98 113 if ( $private_key == null || $private_key== '') {99 if (get_option('mmbpcapt_private') == null || get_option('mmbpcapt_private') == '') { 114 100 die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>"); 115 101 } … … 120 106 121 107 $query = array( 122 'secret' => $private_key,123 'response' => $_POST['g-recaptcha-response'],124 'remoteip' => $_SERVER['REMOTE_ADDR']125 );108 'secret' => get_option('mmbpcapt_private'), 109 'response' => $_POST['g-recaptcha-response'], 110 'remoteip' => $_SERVER['REMOTE_ADDR'] 111 ); 126 112 127 113 $url = 'https://www.google.com/recaptcha/api/siteverify'; … … 129 115 $result = $request->request( $url, array( 'method' => 'POST', 'body' => $query) ); 130 116 131 $response = $result['response'];132 $body = json_decode( $result['body']);117 $response = $result['response']; 118 $body = json_decode( $result['body']); 133 119 134 if ($response['message'] != 'OK' || $body->success != true) { 135 foreach ($body->{'error-codes'} as $error_code) { 136 if ($error_code == 'missing-input-response') { 137 $error_string .= 'You must prove you are human. '; 138 } else { 139 $error_string .= 'There was an error ('.$error_code.') in reCaptcha. '; 140 } 141 } 142 $bp->signup->errors['recaptcha_response_field'] = $error_string; 120 if ($response['message'] != 'OK' || $body->success != true) { 121 foreach ($body->{'error-codes'} as $error_code) { 122 if ($error_code == 'missing-input-response') { 123 $error_string .= 'You must prove you are human. '; 124 } else { 125 $error_string .= 'There was an error ('.$error_code.') in reCaptcha. '; 126 } 143 127 } 128 $bp->signup->errors['recaptcha_response_field'] = $error_string; 129 } 144 130 145 131 return; 146 132 } 147 148 -
buddypress-nocaptcha-register-box/trunk/readme.txt
r1136908 r1137085 3 3 Author URI: http://www.mokummusic.com 4 4 Donate Link: http://www.mokummusic.com 5 Tags: spam, google, captcha, buddypress, anti-spam, recaptcha, nocaptcha, registration, user, form, security5 Tags: spam, google, captcha, buddypress, anti-spam, spambot, bot, recaptcha, nocaptcha, registration, user, form, security 6 6 Requires at least: 3.2 7 7 Tested up to: 4.1 8 Stable tag: 1. 08 Stable tag: 1.1 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html 11 11 12 This super-lightweight plugin adds a Google's No Captcha human friendly reCAPTCHA box to the BuddyPress registration form. 12 Super-lightweight plugin adds Google's No Captcha reCAPTCHA box to your BuddyPress registration form. 13 14 Tough on bots, Easy on humans! 13 15 14 16 == Description == … … 18 20 You also need to enter your API keys from Google in the settings page. You can choose light or dark theme and add basic CSS styling to the box. 19 21 20 It should help keep your community free from spam mers and also hopefully not be too much of a inconvenience for your site's users.22 It should help keep your community free from spambots and also hopefully not be too much of a inconvenience for your sites genuine users. 21 23 22 Uses Google’s new No Captcha reCaptcha API! 24 You can set a dark or light theme. The type of captcha can be set to image or audio and there are over 30 languages available for the NoCaptcha box. Or, set it to auto, based on the users browser language. 25 26 (Plugin code based on Buddypress ReCaptacha by Hardeep Asrani, modified for latest reCaptcha API.) 23 27 24 28 == Installation == … … 47 51 Initial Release. 48 52 53 = 1.1 = 54 Added Languages and async script loading. 55 49 56 == Upgrade Notice == 50 57 51 58 = 1.0 = 52 59 Initial Release. 60 61 = 1.1 = 62 Added Languages and async script loading.
Note: See TracChangeset
for help on using the changeset viewer.