【问题标题】:Protect Returns & Warranty Requests from other users in Woocommerce保护 Woocommerce 中其他用户的退货和保修请求
【发布时间】:2018-12-22 15:26:45
【问题描述】:

有什么方法可以保护WooCommerce Returns & Warranty Requests插件的请求/状态页面(我创建的页面的slug是“returns”)免受订单号或保修请求号不属于的用户的影响?

在默认模式下,页面对公众开放,因此,即使访问者访问此网址 .../my-account/returns/?order=35 也可以看到所有保修请求的详细信息原始用户要求,有什么方法可以保护这个页面?我想使用一个代码来检查用户是否未登录,如果订单号或保修请求号不属于已登录的用户,则不要显示 /returns/ 页面。

我能够在我的 functions.php 中使用此代码来防止未登录的用户看到 /returns/ 页面:

function template_redirect_returns()
{
    if( is_page(returns) && !is_user_logged_in() )
    {
        $loginUrl = home_url('/my-account/orders/');
        wp_redirect($loginUrl);
         exit();
    }
}
add_action( 'template_redirect', 'template_redirect_returns' );

但是,如果 ?order=35 不属于他们,我如何才能阻止用户看到该页面?

我询问了插件开发人员,也报告了许多错误,但他们并不关心修复这些问题。

感谢您的帮助!怀着感激之情。

【问题讨论】:

    标签: php wordpress woocommerce endpoint account


    【解决方案1】:

    在您的代码中,is_page(returns) 应替换为 is_page('returns'),因为它会引发错误。

    尝试以下(未经测试):

    add_action( 'template_redirect', 'template_redirect_returns' );
    function template_redirect_returns()
    {
        if( is_page('returns') ) { 
            if( ! is_user_logged_in() ) {
                wp_redirect( home_url('/my-account/') ); //  instead of '/my-account/orders/'
                 exit();
            }
            // For logged in users
            else {
                // Testing if current user ID match with order customer ID
                if( isset($_GET['order']) && get_post_meta( $_GET['order'], '_customer_user', true ) != get_current_user_id() ){
                    wp_redirect( home_url('/my-account/orders/') );
                    exit();
                }
            }
        }
    }
    

    这是此插件中真正的安全漏洞,应通知作者

    【讨论】:

    • 感谢您的快速响应以及您为解决此错误所做的努力。我尝试了您提供的代码,它可以正常工作,但是如果我们使用 is_page insted of is_wc_endpoint_url
    • @tatifox 谢谢我已经更新了代码放回is_page()...
    猜你喜欢
    • 2022-01-09
    • 2011-03-05
    • 2011-02-11
    • 1970-01-01
    • 1970-01-01
    • 2021-08-22
    • 1970-01-01
    • 2015-10-15
    • 2019-01-25
    相关资源
    最近更新 更多