• Resolved amosnier

    (@amosnier)


    Hi, I added the entire filter described in the section “How to whitelist certain IPs” in the file functions.php while changing only ‘1.1.1.1’ with my own IP number, but doesn’t work and the hCaptcha is ever shown. Have you an idea ?

    // Whitelist some other IPs.
    if ( ‘1.1.1.1’ === $ip ) {
    return true;

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author hcaptcha

    (@hcaptcha)

    Hi, please paste a larger snippet + line number showing where you put the code.

    Thread Starter amosnier

    (@amosnier)

    Here are the lines added to the file functions.php of my theme. There are fully identical to the lines of the section “How to whitelist certain IPs” in the FAQ of the plugin, but I changed ‘1.1.1.1’ to my actual IP number.

    // hCaptcha filtre ajouté to whitelist certain IPs
    /**
    * Filter user IP to check if it is whitelisted.
    * For whitelisted IPs, hCaptcha will not be shown.
    *
    * @param bool   $whitelisted Whether IP is whitelisted.
    * @param string $ip          IP.
    *
    * @return bool
    */
    function my_hcap_whitelist_ip( $whitelisted, $ip ) {
      // Whitelist local IPs.
      if ( false === $ip ) {
        return true;
      }
      // Whitelist some other IPs.
      if ( '1.1.1.1' === $ip ) {
        return true;
      }
      return $whitelisted;
    }
    Plugin Contributor kaggdesign

    (@kaggdesign)

    I do not see here the crucial line, which causes the function to work:

    
    add_filter( 'hcap_language', 'my_hcap_language' );
    
    Thread Starter amosnier

    (@amosnier)

    Sorry, when I copied the lines from my functions.php file, I missed the last line that was well present in the file :

    // hCaptcha filtre ajouté to whitelist certain IPs
    /**
    * Filter user IP to check if it is whitelisted.
    * For whitelisted IPs, hCaptcha will not be shown.
    *
    * @param bool   $whitelisted Whether IP is whitelisted.
    * @param string $ip          IP.
    *
    * @return bool
    */
    function my_hcap_whitelist_ip( $whitelisted, $ip ) {
      // Whitelist local IPs.
      if ( false === $ip ) {
        return true;
      }
      // Whitelist some other IPs.
      if ( '1.1.1.1' === $ip ) {
        return true;
      }
      return $whitelisted;
    }
    add_filter( 'hcap_whitelist_ip', 'my_hcap_whitelist_ip', 10, 2 );

    the line
    add_filter( 'hcap_language', 'my_hcap_language' );
    is in principle used when we want to set hCaptcha language programmatically.
    See
    https://fr.wordpress.org/plugins/hcaptcha-for-forms-and-more/#how%20to%20whitelist%20certain%20ips
    But This filter snippet seems not to work for me …

    Plugin Contributor kaggdesign

    (@kaggdesign)

    Apologies ))) I have copied the wrong line. You are right – you need

    
    add_filter( 'hcap_whitelist_ip', 'my_hcap_whitelist_ip', 10, 2 );
    

    If it does not work, it means that we cannot detect your IP address correctly. Please try to insert var_dump( $ip ) at the beginning of the my_hcap_whitelist_ip function.

    Also, could you provide the URL of your website?

    Thread Starter amosnier

    (@amosnier)

    I added var_dump( $ip ); but does’nt improve.
    URL of the website : https://attacn91.fr/

    Thanks for your help.

    Plugin Contributor kaggdesign

    (@kaggdesign)

    I do not see any output of var_dump( $ip ) on the page. Can you make it work?

    So far, it looks like your filter is placed in the wrong file and does not work, therefore.

    Thread Starter amosnier

    (@amosnier)

    OK, when I displayed $ip, it was returned “null”. So I added first the line
    $ip = $_SERVER['REMOTE_ADDR'];
    and the IP number is now well defined (ipv6).
    But I don’t now actually in which file I have to add the snippet for the login. Up to now, I put it in the functions.php file, but it shouldn’t be the right place, because it doesn’t work. Hace you an idea where to put this snippet for the login session ?

    Plugin Contributor kaggdesign

    (@kaggdesign)

    Something is wrong with the above. First, $ip inside of the my_hcap_whitelist_ip cannot be null in any case. It can be a string with an IP address or false for a local IP address.

    Secondly, there are contradictions in your reports: IP number is now well defined (ipv6), but `it doesn’t work. It looks like you need a developer with access to your site to help. Unfortunately, according to the rules of wp.org, we cannot ask for any access to your site.

    It seems that the problem is not in the plugin and IP detection functionality.

    Thread Starter amosnier

    (@amosnier)

    So, I forced the function added in the theme’s function.php file to be true :

    function my_hcap_whitelist_ip( $whitelisted, $ip ) {
    	return true;
    	return $whitelisted;
    }
    add_filter( 'hcap_whitelist_ip', 'my_hcap_whitelist_ip', 10, 2 );

    but the hCaptcha is still present when I log in.
    Maybe is this filter only valid for the pro version ?

    Thread Starter amosnier

    (@amosnier)

    It works now ! I simply moved the filter from the functions.php file of my theme to the functions.php file of the plugin (/src/php/includes/common).
    Don’t understand why it is not working in the functions of my theme.
    But it works now …

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘hcap whitelist’ is closed to new replies.