Redirect 如何使用url阻止对多个感谢页面的直接访问?

Redirect 如何使用url阻止对多个感谢页面的直接访问?,redirect,Redirect,我在我的wordpress网站上有多个联系方式,每个都有一个不同的感谢页面。所以,我想通过输入URL来阻止直接访问thankyou页面。如果用户填写表单,我希望它只重定向到表单感谢页面 我有1个感谢页面的工作代码,但我不知道如何设置多个联系人表单和感谢页面 if ( ! is_page(1911)) { return; } // coming from the form, so all is fine if (wp_get_referer() =

我在我的wordpress网站上有多个联系方式,每个都有一个不同的感谢页面。所以,我想通过输入URL来阻止直接访问thankyou页面。如果用户填写表单,我希望它只重定向到表单感谢页面

我有1个感谢页面的工作代码,但我不知道如何设置多个联系人表单和感谢页面

    if ( ! is_page(1911)) {
        return;
    }

    // coming from the form, so all is fine
    if (wp_get_referer() == 'https://www.example.com/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.com/contact-form-2, https://www.example.com/contact-form-3, https://www.example.com/contact-form-3

我自己解决了这个问题。我在这里发布解决方案,以防有人遇到同样的问题

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