• Resolved inspry

    (@inspry)


    We are using following code to whitelist specific IP’s while submitting ninja forms in one of our clients site.

    /**
     * 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 );

    Issue is that, this code does not hide hCaptcha from the from but just allows the submission without attempting it. ( Form submits without any issues even if you don’t attempt hCaptcha ).
    We want it to be hidden as it actually gets hidden when we add IP address manually in the whitelist settings field.
    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor kaggdesign

    (@kaggdesign)

    This code must be added to your plugin’s (or mu-plugin’s) main file. It won’t work being added to a theme’s functions.php file.

    Thread Starter inspry

    (@inspry)

    Hi there!
    Thanks for your response.
    Yes we did added this chunk is main file of our plugin.
    But when we submit the form it returns internal server error. Looks like ninja forms is looking for hCaptcha field but it’s not available.
    Thanks!
    https://app.screencast.com/reNcadrMUQg39

    Plugin Contributor kaggdesign

    (@kaggdesign)

    Hi @inspry,

    Thank you for providing the screenshot. Unfortunately, it does not contain a useful stuff. I need a debug.log information.

    Also, if your plugin name is textually greater than “hcaptcha-for-forms-and-more”, you code runs too late. Plugins are loaded in the alphabetic order.

    Therefor, a mu-plugin is a safe solution.

    • This reply was modified 3 months, 1 week ago by kaggdesign.
    Thread Starter inspry

    (@inspry)

    Hi there thanks for your help!
    Actually the issue is when we add our IP address to whitelisting settings. It hides the hCaptcha but returns error 500 on submit.
    Attached below is the magic link to the site where you can add your IP address to whitelist settings and submit the ninja form on sample page of the site. We think IP address whitelisting feature is not compatible with NinjaForms. As Ninja forms return error when hCaptcha is not found in form.

    https://app.instawp.io/wordpress-auto-login?site=$2y$10$t2qh/2JkNtvrZK3CpwXR1eUefa3/Aw5JSPRdGiNLX5nZkA/DQObqa

    https://unparalleled-goosander-8eda67.instawp.xyz/sample-page/
    Thanks!

    Plugin Contributor kaggdesign

    (@kaggdesign)

    Thank you for extended explanations. The bug is actually in Ninja Forms.

    In the file wp-content/plugins/ninja-forms/includes/AJAX/Controllers/Submission.php, method \NF_AJAX_Controllers_Submission::process_field the line

    $field_class = Ninja_Forms()->fields[ $field_settings['type'] ];

    should be

    $field_class = Ninja_Forms()->fields[ $field_settings['type'] ] ?? '';

    $field_class can be null in their code, that is why next line produces a fatal error.

    You can propose this this fix to Ninja Form developers.

    Thank you for your help, we have sent that to Ninja Forms for their next release.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.