is_user_logged_in与wp_redirect冲突

我试图对未登录的用户隐藏我的自定义帖子类型单页。我使用钩子template_redirect如下:

add_action('template_redirect', 'hide_single_property');
function hide_single_property()
{
    if( is_singular('property') || is_page('dashboard')):
        if( ! is_user_logged_in() ):
            wp_redirect(get_permalink(103), 302);
            exit;
        endif;
    endif;      
}

上面的代码有效, 但存在一些问题。就像我尝试访问http://example.com/property/abc一样, 它会重定向到登录页面。登录后, 如果我尝试访问相同的帖子, 它将再次重定向回登录页面, 但是可以与其他属性一起正常使用。

它只是在再次登录之前加载URL 🙁


#1


如果仅是你要隐藏的单个帖子, 则可以将以下内容添加到sinlge-property.php模板文件中:

if ( is_user_logged_in() ) { 
   //your content file 
     get_template_part('content'); 
} 
else {
   //show login page  
     get_template_part('must-login'); 
}

来源:

https://www.srcmini02.com/65547.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37272.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?