wp redirect - how to block direct access to multiple thank you pages?

I have multiple contact forms in my wordpress website and have a different thankyou page for each.So, i want to prevent

I have multiple contact forms in my wordpress website and have a different thankyou page for each. So, i want to prevent direct access of thankyou pages by just entering urls. I want if the user fills the form than it is only redirected to that forms thankyou page.

I have working code for 1 thankyou page but i don't know how to set up for multiple contact forms & thankyou pages.

    // ID of the thank you page
    if ( ! is_page(1911)) {
        return;
    }

    // coming from the form, so all is fine
    if (wp_get_referer() == '') {
        return;
    }

    // we are on thank you page
    // visitor is not coming from form
    // so redirect to home
    wp_redirect( get_home_url() );
    exit;
} );```

Other thankyou page id's: 1269, 1825, 1623
Other contact form page urls: , , 

I have multiple contact forms in my wordpress website and have a different thankyou page for each. So, i want to prevent direct access of thankyou pages by just entering urls. I want if the user fills the form than it is only redirected to that forms thankyou page.

I have working code for 1 thankyou page but i don't know how to set up for multiple contact forms & thankyou pages.

    // ID of the thank you page
    if ( ! is_page(1911)) {
        return;
    }

    // coming from the form, so all is fine
    if (wp_get_referer() == 'https://www.example/contact') {
        return;
    }

    // we are on thank you page
    // visitor is not coming from form
    // so redirect to home
    wp_redirect( get_home_url() );
    exit;
} );```

Other thankyou page id's: 1269, 1825, 1623
Other contact form page urls: https://www.example/contact-form-2, https://www.example/contact-form-3, https://www.example/contact-form-3
Share Improve this question asked Apr 17, 2020 at 5:29 Ujjawal PooniaUjjawal Poonia 214 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

I have solved the issue by myself. I am posting the solution here in case if someone gets the same problem.

function wpse15677455_redirect() {
    $ref = wp_get_referer();
    if (is_page(1911) && $ref !== "https://www.example/contact"){
       wp_redirect( get_home_url() );
    }
    else if(is_page(1269) && $ref !== "https://www.example/contact-form-2"){
        wp_redirect( get_home_url() );
    }
    else if(is_page(1825) && $ref !== "https://www.example/contact-form-3"){
        wp_redirect( get_home_url() );
    }
    else if(is_page(1623) && $ref !== "https://www.example/contact-form-4"){
        wp_redirect( get_home_url() ); exit();
 };

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742418468a4440202.html

相关推荐

  • wp redirect - how to block direct access to multiple thank you pages?

    I have multiple contact forms in my wordpress website and have a different thankyou page for each.So, i want to prevent

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信