weDevsOfficial / wp-recaptcha-integration

WordPress reCaptcha integration supporting Ninja Forms and Contact Form 7
https://wordpress.org/plugins/wp-recaptcha-integration
50 stars 32 forks source link

recaptcha javascript being included inline in html - also whether there is a login form or not #71

Open gekidoslair opened 8 years ago

gekidoslair commented 8 years ago

have this setup on a site, and there are a few issues with the javascript usage:

1) it's being included on every page whether there is a login form on the page or not.

2) the javascript is just being dumped into the html of the page instead of being included as a separate .js file - is there a reason for this?

Thanx - awesome plugin!

patschi commented 8 years ago

Regarding your first point it would be possible to just return "true" when calling "is_required()" if the current page is either the login or register page. When it is enabled on the comment form, it could be displayed on nearly every page.

I'm currently using my following modified code in https://github.com/mcguffin/wp-recaptcha-integration/blob/654c39efeae56b7f8b2299d712f3c4f0b8e8db94/inc/class-wp_recaptcha.php#L217-L220:

function is_required() {
    $is_required = ! ( $this->get_option('recaptcha_disable_for_known_users') && is_user_logged_in() );
    if ( $is_required && ! $this->get_option('recaptcha_enable_comments') ) {
        if ( ! in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) ) {
            $is_required = false;
        }
    }
    return apply_filters( 'wp_recaptcha_required' , $is_required );
}