• Resolved cari18

    (@cari18)


    HEY Kevin
    I use Force Login for my website which is for an association so you can access to site’ pages only by login: Force login is great for that !
    Nevertheless I have a public page (that I added in Functions.php as whitelist) to present association to everybody.
    On this public page (see link above) I added a form with Contact Form 7 extension, so people can send email to association to ask information.
    Unfortunately it does not work and below here is the message I get on navigator console.
    Do you know a way to bypass this issue please ?

    jquery.js?ver=1.12.4:4 POST https://sitesdu.fr/wp-json/contact-form-7/v1/contact-forms/2737/feedback 401
    send @ jquery.js?ver=1.12.4:4
    ajax @ jquery.js?ver=1.12.4:4
    wpcf7.submit @ scripts.js?ver=5.1.1:341
    (anonymous) @ scripts.js?ver=5.1.1:56
    dispatch @ jquery.js?ver=1.12.4:3
    r.handle @ jquery.js?ver=1.12.4:3

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Kevin Vess

    (@kevinvess)

    Hi, thanks for using Force Login!

    Force Login already has an exception for AJAX submissions; I assume after the submission, the contact form tries to load a new page URL / thank you page?

    You might also need to bypass / whitelist the form’s thank you page.

    Try using the v_forcelogin_bypass filter to whitelist your public page using the is_page() function. See the FAQ for an example of this filter.

    Thread Starter cari18

    (@cari18)

    Thank you Kevin for answer.
    The contact form would normaly answer by a thank you line at the bottom of the current page, under the form

    My public page is : https://sitesdu.fr/les-anciens-de-nestle/

    Here is what I tried :

    function my_forcelogin_bypass( $bypass ) {
    if ( is_page(‘sitesdu.fr/wp-json/contact-form-7/v1/contact-forms/2737/feedback’) ) {
    $bypass = true;
    }
    return $bypass;
    }
    add_filter( ‘v_forcelogin_bypass’, ‘my_forcelogin_bypass’ );

    /**
    * Filter Force Login to allow exceptions for specific URLs.
    *
    * @param array $whitelist An array of URLs. Must be absolute.
    * @return array
    */
    function my_forcelogin_whitelist( $whitelist ) {
    $whitelist[] = home_url( ‘/privacy-policy/’ );
    $whitelist[] = home_url( ‘/les-anciens-de-nestle/’ );
    $whitelist[] = home_url( ‘/wp-json/contact-form-7/v1/contact-forms/2737/feedback/’ );
    return $whitelist;
    }
    add_filter( ‘v_forcelogin_whitelist’, ‘my_forcelogin_whitelist’ );

    And it still don’t work
    I’m Sorry but Unfortunately I’m not very comfortable with coding!

    Plugin Author Kevin Vess

    (@kevinvess)

    Hi– thanks for sharing your code, that’s helpful.

    I see you’re not using the functions correctly; try changing these to the following:

    function my_forcelogin_bypass( $bypass ) {
        $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
    
        if ( is_page('les-anciens-de-nestle') || is_page( $policy_page_id ) ) {
            $bypass = true;
        }
        return $bypass;
    }
    add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass' );

    OR

    /**
    * Filter Force Login to allow exceptions for specific URLs.
    *
    * @param array $whitelist An array of URLs. Must be absolute.
    * @return array
    */
    function my_forcelogin_whitelist( $whitelist ) {
        $whitelist[] = get_privacy_policy_url();
        $whitelist[] = home_url( '/les-anciens-de-nestle/' );
    return $whitelist;
    }
    add_filter( 'v_forcelogin_whitelist', 'my_forcelogin_whitelist' );
    • This reply was modified 5 years, 11 months ago by Kevin Vess. Reason: Fixed quotation marks in code
    Plugin Author Kevin Vess

    (@kevinvess)

    Also, try adding this line to your functions.php to disable Force Login’s REST API restriction:

    add_filter( 'rest_authentication_errors', '__return_true' );
    
    Thread Starter cari18

    (@cari18)

    Thank a lot Kevin! It works well
    YOU ARE GREAT !!!
    Its incredible you support me so efficiently
    Take care

    Thread Starter cari18

    (@cari18)

    I mark the point as resolved

    Plugin Author Kevin Vess

    (@kevinvess)

    Excellent, I’m glad you got it working!

    Be sure to rate and review my plugin to let others know how you like it.

    Thanks for using Force Login!

    Thread Starter cari18

    (@cari18)

    Sure already done !

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Contact form in a whitelisted page’ is closed to new replies.