Skip to content

Commit

Permalink
add expired callback, reduce conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mcguffin committed Oct 15, 2017
1 parent 6a4f822 commit 17b9f04
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 123 deletions.
14 changes: 8 additions & 6 deletions inc/class-wp_recaptcha_nocaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ private function __construct() {
public function register_assets() {

$recaptcha_api_url = "https://www.google.com/recaptcha/api.js";
$recaptcha_api_url = add_query_arg(array(
'onload' => 'wp_recaptcha_loaded',
'render' => 'explicit',
),$recaptcha_api_url);
$recaptcha_api_url = add_query_arg( array(
'onload' => 'wp_recaptcha_loaded',
'render' => 'explicit',
),$recaptcha_api_url);

if ( $language_code = apply_filters( 'wp_recaptcha_language' , WP_reCaptcha::instance()->get_option( 'recaptcha_language' ) ) ) {
$recaptcha_api_url = add_query_arg( 'hl', $language_code, $recaptcha_api_url );
Expand Down Expand Up @@ -180,13 +180,15 @@ public function get_html( $attr = array() ) {

$default = array(
'id' => 'g-recaptcha-'.$this->_counter++,
'class' => "g-recaptcha wp-recaptcha",
'class' => "wp-recaptcha",
'data-theme' => $theme,
'data-size' => $size,
'data-callback' => $inst->get_option( 'recaptcha_solved_callback'),
);
$attr = wp_parse_args( $attr , $default );

if ( WP_reCaptcha::instance()->get_option('recaptcha_noscript') ) {
$attr['class'] .= ' g-recaptcha';
}

$attr_str = '';
foreach ( $attr as $attr_name => $attr_val ) {
Expand Down
61 changes: 10 additions & 51 deletions js/wp-recaptcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,30 @@
if ( ! grecaptcha ) {
return;
}

$captchas.each(function(i,el){
var $form = $(el).closest('form');
var opts = {
sitekey : wp_recaptcha.site_key,
theme : $(el).attr('data-theme'),
size : $(el).attr('data-size'),
},
callbacks = {
enable : function(){
$form.find('[type="submit"]').prop( 'disabled', false );
},
},
cb = $(el).attr('data-callback'),
submitInterval;

if ( cb !== '' ) {
opts.callback = callbacks.enable;

opts.callback = function() {
$form.find('[type="submit"]').prop( 'disabled', false );
};
opts.expiredCallback = function() {
$form.find('[type="submit"]').prop( 'disabled', true );
}

if ( ! $form.find('[type="submit"]').prop( 'disabled', true ).length ) {
$form.append('<input type="submit" style="visibilit:hidden;width:1px;height;1px;" />')
}

if ( cb == 'submit' && $form.find('[type="submit"]').length ) {
submitInterval = setInterval(function(){
if ( ! $form.find('[type="submit"]').prop( 'disabled' ) ) {
Expand All @@ -49,48 +53,3 @@


})(jQuery);

// var recaptcha_widgets={};
// function wp_recaptchaLoadCallback() {
// try {
// grecaptcha;
// } catch(err){
// return;
// }
// var e = document.querySelectorAll('.g-recaptcha.wp-recaptcha'),
// form_submits;
// console.log(e[i]);
//
// for (var i=0;i<e.length;i++) {
// (function(el){
// <?php if ( WP_reCaptcha::instance()->get_option( 'recaptcha_disable_submit' ) ) { ?>
// var form_submits = get_form_submits(el).setEnabled(false), wid;
// <?php } else { ?>
// var wid;
// <?php } ?>
// // check if captcha element is unrendered
// if ( ! el.childNodes.length) {
// wid = grecaptcha.render(el,{
// 'sitekey':'<?php echo $sitekey ?>',
// 'theme':el.getAttribute('data-theme') || '<?php echo WP_reCaptcha::instance()->get_option('recaptcha_theme'); ?>',
// 'size':el.getAttribute('data-size') || '<?php echo WP_reCaptcha::instance()->get_option('recaptcha_size'); ?>'
// <?php if ( WP_reCaptcha::instance()->get_option( 'recaptcha_disable_submit' ) ) {
// ?> ,
// 'callback' : function(r){ get_form_submits(el).setEnabled(true); /* enable submit buttons */ }
// <?php } ?>
// });
// el.setAttribute('data-widget-id',wid);
// } else {
// wid = el.getAttribute('data-widget-id');
// grecaptcha.reset(wid);
// }
// })(e[i]);
// }
// }
//
// // if jquery present re-render jquery/ajax loaded captcha elements
// if ( typeof jQuery !== 'undefined' )
// jQuery(document).ajaxComplete( function(evt,xhr,set){
// if( xhr.responseText && xhr.responseText.indexOf('<?php echo $sitekey ?>') !== -1)
// wp_recaptchaLoadCallback();
// } );
4 changes: 2 additions & 2 deletions js/wp-recaptcha.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 4 additions & 13 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,14 @@ running under his/her own domain name.


= Known Limitations =
- You can't have more than one old style reCaptcha on a page. This is a limitiation of
reCaptcha itself. If that's an issue for you, you should use the no Captcha Form.

- A No Captcha definitely requires client side JavaScript enabled. That's how it does its
sophisticated bot detection magic. There is no fallback. If your visitor does not have
JS enabled the captcha test will not let him through.

- On a **Contact Form 7** when the reCaptcha is disabled (e.g. for logged in users) the field
label will be still visible. This is due to CF7 Shortcode architecture, and can't be fixed.

To handle this there is a filter `recaptcha_disabled_html`. You can return a message for your logged-in
users here. Check out the [GitHub Repo](https://github.com/mcguffin/wp-recaptcha-integration) for details.

- As of version 4.3 CF7 comes with its own recaptcha. Both are supposed to work together.
I you want to keep the WP ReCaptcha functionality, e.g. if you want to hide the captcha
from known users, leave the integration in the CF7 settings unconfigured.

- Old style reCaptcha does not work together with **WooCommerce**.

- In **WooCommerce** the reset password form can not be protected by a captcha. Woocommerce does
not fire any action in the lost password form, so there is no way for the plugin to hook in.
Take a look at [this thread](https://wordpress.org/support/topic/captcha-not-showing-on-lost-password-page?replies=7) for a workaround.
Expand Down Expand Up @@ -246,13 +235,15 @@ Please contribute to the official (translation Project for the ReCaptcha Plugin)

1. Plugin Settings (v 1.1.4)

== Upgrade Notice ==

== Changelog ==

= 1.3.0 =
- Drop most of Contact form 7 and Ninja Forms support. (Both have thir own recaptcha now)
- Drop most of Contact form 7 and Ninja Forms support. (Both have their own recaptcha now)
- Deprecate recaptcha v1.
- New Option: size
- New Option: Size
- New Option: Submit form when captcha is solved
- Cleanup options page
- Register Form compatibility with WooCommerce 3.0+ Thanks to [ywatt](https://github.com/ingomarent) and [MrFent37](https://wordpress.org/support/users/mrfent37/)

Expand Down
Loading

0 comments on commit 17b9f04

Please sign in to comment.