Plugin Directory

Changeset 1137085


Ignore:
Timestamp:
04/17/2015 12:36:27 PM (11 years ago)
Author:
mokummusic
Message:

V1.1 Upgrade. Adds Languages, Type and async loading

Location:
buddypress-nocaptcha-register-box/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • buddypress-nocaptcha-register-box/trunk/mmbp-nocaptcha.php

    r1136908 r1137085  
    44Plugin URI: http://www.functionsphp.com/recaptcha
    55Description: 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
     6It should help keep your community free from spambots and also hopefully not be too much of a inconvenience for your sites genuine users.
     7You 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.)
     9Version: 1.1
    910Author: Neil Foster
    1011Author URI: http://www.mokummusic.com
     
    1819function enqueue_mokum_nocaptcha_scripts() {
    1920
    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');
    2225}
    2326add_action( 'wp_enqueue_scripts', 'enqueue_mokum_nocaptcha_scripts');
     27
     28
     29// Make recaptcha script load asynchronously
     30add_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
    2435
    2536// ********** ADMIN SETTINGS FUNCTIONS **************
    2637
    2738function 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');
    3150    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' );
    3651}
    3752add_action('admin_init', 'mmbpcapt_init' );
    38  
     53
    3954function mmbpcapt_register_options_page() {
    4055    add_options_page('BuddyPress noCaptcha', 'BuddyPress noCaptcha', 'manage_options', 'bp-captcha', 'mmbpcapt_options_page');
    4156}
    4257add_action('admin_menu', 'mmbpcapt_register_options_page');
    43  
     58
    4459function 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';
    8161}
    8262
    8363// ********** FRONT END **************
    8464
    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    
    9065add_action( 'bp_before_registration_submit_buttons', 'bp_add_code' );
    9166add_action( 'bp_signup_validate', 'bp_validate' );
    9267
    9368function 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    ?>
    9771
    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
    10894}
    10995
    11096function bp_validate() {
    111     global $bp, $private_key;
     97    global $bp;
    11298
    113     if ($private_key == null || $private_key == '') {
     99    if (get_option('mmbpcapt_private') == null || get_option('mmbpcapt_private') == '') {
    114100        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>");
    115101    }
     
    120106
    121107    $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        );
    126112
    127113    $url = 'https://www.google.com/recaptcha/api/siteverify';
     
    129115    $result = $request->request( $url, array( 'method' => 'POST', 'body' => $query) );
    130116
    131         $response = $result['response'];
    132         $body = json_decode( $result['body']);
     117    $response = $result['response'];
     118    $body = json_decode( $result['body']);
    133119
    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            }   
    143127        }
     128        $bp->signup->errors['recaptcha_response_field'] = $error_string;
     129    }
    144130
    145131    return;
    146132}
    147 
    148 
  • buddypress-nocaptcha-register-box/trunk/readme.txt

    r1136908 r1137085  
    33Author URI: http://www.mokummusic.com
    44Donate Link: http://www.mokummusic.com
    5 Tags: spam, google, captcha, buddypress, anti-spam, recaptcha, nocaptcha, registration, user, form, security
     5Tags: spam, google, captcha, buddypress, anti-spam, spambot, bot, recaptcha, nocaptcha, registration, user, form, security
    66Requires at least: 3.2
    77Tested up to: 4.1
    8 Stable tag: 1.0
     8Stable tag: 1.1
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1111
    12 This super-lightweight plugin adds a Google's No Captcha human friendly reCAPTCHA box to the BuddyPress registration form.
     12Super-lightweight plugin adds Google's No Captcha reCAPTCHA box to your BuddyPress registration form.
     13
     14Tough on bots, Easy on humans!
    1315
    1416== Description ==
     
    1820You 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.
    1921
    20 It should help keep your community free from spammers and also hopefully not be too much of a inconvenience for your site's users.
     22It should help keep your community free from spambots and also hopefully not be too much of a inconvenience for your sites genuine users.
    2123
    22 Uses Google’s new No Captcha reCaptcha API!
     24You 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.)
    2327
    2428== Installation ==
     
    4751Initial Release.
    4852
     53= 1.1 =
     54Added Languages and async script loading.
     55
    4956== Upgrade Notice ==
    5057
    5158= 1.0 =
    5259Initial Release.
     60
     61= 1.1 =
     62Added Languages and async script loading.
Note: See TracChangeset for help on using the changeset viewer.