• Resolved koniahin

    (@koniahin)


    The plugin options under Main Functionality include the option:
    Enable this plugin for
    I check only Comment form but I see that the Javascript is enabled on all website pages including those that are not blog-related. How do you fix this so that it is only enabled on blog/comment pages.

    I tried editing the plugin file, bwp-recaptcha.php, and adding some if statements, such as if is_home, is_page, etc. but these are ignored. Maybe I didn’t have the location or correct is_ statement. Or was editing the wrong file? Please assist.

    https://www.ads-software.com/plugins/bwp-recaptcha/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Khang Minh

    (@oddoneout)

    Hi,

    For now you can use the template_redirect action hook to NOT print captcha javascript on certain pages, for example:

    add_action('template_redirect', 'exclude_recaptcha_js');
    function exclude_recaptha_js()
    {
        global $bwp_capt;
        if (!is_singular()) {
            remove_action('wp_footer', array($bwp_capt->get_captcha_provider(), 'printRecaptchaJS'), 99999);
        }
    }
    
    Thread Starter koniahin

    (@koniahin)

    In what folder/file do I add the function and action, and approximately where (following what code) does it get inserted?

    I’m not familiar with is_singular. Is that a wp test something like is_page()?

    Tx

    Plugin Author Khang Minh

    (@oddoneout)

    You can add the above codes to your theme’s functions.php. And yes, is_singular is something like is_page, but it supports custom post types, more info here: https://codex.www.ads-software.com/Function_Reference/is_singular

    Thread Starter koniahin

    (@koniahin)

    Thx, however there must be something in the code that is amiss. I added it exactly as seen to the end of the functions.php file and it results in blank (white) pages when you visit the website. Over …

    Plugin Author Khang Minh

    (@oddoneout)

    Sorry, it should be:

    add_action('template_redirect', 'exclude_recaptcha_js');
    function exclude_recaptcha_js()
    {
        global $bwp_capt;
        if (!is_singular()) {
            remove_action('wp_footer', array($bwp_capt->get_captcha_provider(), 'printRecaptchaJS'), 99999);
        }
    }
    
    Thread Starter koniahin

    (@koniahin)

    Thx again but it still results in blank page(s). If I comment out the add_action line, pages are good but of course that does not solve the problem.

    Plugin Author Khang Minh

    (@oddoneout)

    Can you try enabling WP_DEBUG (https://codex.www.ads-software.com/WP_DEBUG) and then refresh the page to see the actual error? I tested the above snippet and it worked for me.

    Thread Starter koniahin

    (@koniahin)

    The error with wp_debug enabled:

    Fatal error: Call to undefined function add_action() in /home/matthelm/public_html/wp-includes/functions.php on line 5175

    I placed the function at the end of ~/www/wp-includes/functions.php following the mysql_to_rfc3339 function like the following:

    function mysql_to_rfc3339( $date_string ) {
    $formatted = mysql2date( ‘c’, $date_string, false );

    // Strip timezone information
    return preg_replace( ‘/(?:Z|[+-]\d{2}(?::\d{2})?)$/’, ”, $formatted );
    }

    add_action(‘template_redirect’, ‘exclude_recaptcha_js’);
    function exclude_recaptcha_js()
    {
    global $bwp_capt;
    if (!is_singular()) {
    remove_action(‘wp_footer’, array($bwp_capt->get_captcha_provider(), ‘printRecaptchaJS’), 99999);
    }
    }

    I figured out a ‘hack’ way to resolve this by adding a clause within the _registerHooks() function in the ~/www/wp-content/plugins/bwp-recaptcha/includes/provider/v2.php file, but I would rather not use a hack if it can be avoided. This is not urgent.

    Plugin Author Khang Minh

    (@oddoneout)

    You should add the above snippet to your theme’s functions.php, i.e. /home/matthelm/public_html/wp-content/themes/your-theme/functions.php, NOT /home/matthelm/public_html/wp-includes/functions.php.

    Thread Starter koniahin

    (@koniahin)

    Well that makes a big difference – it works. I am using the following if clause:

    if (!is_singular(‘post’) && ! is_page (‘3321’) )

    This limits the captcha to display on a blog ‘post’ page and on my contact page, ID 3321.

    Nice.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘disable on non-blog pages’ is closed to new replies.