Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contact form 7 recapture compatability issue #100

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion all-in-one-wp-security/classes/wp-security-captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function display_recaptcha_form()
do_action( 'bp_aiowps-captcha-answer_errors' );
}
$site_key = esc_html( $aio_wp_security->configs->get_value('aiowps_recaptcha_site_key') );
$cap_form = '<div class="g-recaptcha-wrap" style="padding:10px 0 10px 0"><div class="g-recaptcha" data-sitekey="'.$site_key.'"></div></div>';
$cap_form = '<div class="g-recaptcha-wrap" style="padding:10px 0 10px 0"><div id="aiowps_recaptcha_field" class="g-recaptcha" data-sitekey="'.$site_key.'"></div></div>';
echo $cap_form;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ function process_comment_post( $comment )
}

//Don't do captcha for pingback/trackback
if ($comment['comment_type'] != '' && $comment['comment_type'] != 'comment') {
if ($comment['comment_type'] != '' && $comment['comment_type'] != 'comment' && $comment['comment_type'] != 'review') {
return $comment;
}

Expand Down
59 changes: 35 additions & 24 deletions all-in-one-wp-security/classes/wp-security-wp-footer-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,27 @@ function __construct() {
if($aio_wp_security->configs->get_value('aiowps_default_recaptcha')) {
// For Woocommerce forms.
// Only proceed if woocommerce installed and active
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) )
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && is_account_page() )
{
if($aio_wp_security->configs->get_value('aiowps_enable_woo_login_captcha') == '1' ||
$aio_wp_security->configs->get_value('aiowps_enable_woo_register_captcha') == '1' ||
$aio_wp_security->configs->get_value('aiowps_enable_woo_lostpassword_captcha') == '1')
{
$this->print_recaptcha_api_woo();
$this->print_recaptcha_api_trigger(array(
'woo_recaptcha_1',
'woo_recaptcha_2'
));
}
}

// ContactForm7 Conflict
// Only proceed if contact form 7 installed and active
elseif ( in_array( 'contact-form-7/wp-contact-form-7.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) )
{
$this->print_recaptcha_api_trigger(array(
'aiowps_recaptcha_field',
));
}

// For custom wp login form
if($aio_wp_security->configs->get_value('aiowps_enable_custom_login_captcha') == '1')
Expand All @@ -41,38 +53,37 @@ function __construct() {

//TODO - add other footer output content here
}

/**
* For Woocommerce my account page - display two separate Google reCaptcha forms "explicitly"
* For Woocommerce my account page / Contactfrom7 - display multiple separate Google reCaptcha forms "explicitly" or single form for compatibility reasons
* @global type $aio_wp_security
*/
function print_recaptcha_api_woo() {
function print_recaptcha_api_trigger($recaptureNames = array()) {
global $aio_wp_security;
$is_woo = false;
$is_woo = is_account_page();
if(!$is_woo) {
return; // if current page is not woo account page don't do anything
}
$site_key = esc_html( $aio_wp_security->configs->get_value('aiowps_recaptcha_site_key') );
?>
<script type="text/javascript">

// Build JS logic
$logicJs = '';
foreach ($recaptureNames as $name) {
$logicJs .= '
if ( jQuery("#' . $name . '").length ) {
grecaptcha.render("' . $name . '", {
"sitekey" : "' . $site_key . '",
});
}
';
}

?>
<script type="text/javascript">
var verifyCallback = function(response) {
alert(response);
};
var onloadCallback = function() {
if ( jQuery('#woo_recaptcha_1').length ) {
grecaptcha.render('woo_recaptcha_1', {
'sitekey' : '<?php echo $site_key; ?>',
});
}
if ( jQuery('#woo_recaptcha_2').length ) {
grecaptcha.render('woo_recaptcha_2', {
'sitekey' : '<?php echo $site_key; ?>',
});
}
<?php echo $logicJs; ?>
};
</script>
<script src='https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit' async defer></script>
</script>
<script src='https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit' async defer></script>
<?php
}

Expand Down