Wordpress强制用户在查看任何网站内容之前先登录 [英] Wordpress force user to login before view any site content

查看:399
本文介绍了Wordpress强制用户在查看任何网站内容之前先登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在wordpress中,我尝试先强制用户登录,然后再看到任何内容.意味着我希望我的用户先登录才能查看任何单个页面,帖子或存档,并且只有他们才能访问FAQ页面.我正在尝试使用下面的代码,但是问题是我登录后立即将其再次重定向到登录页面.

In wordpress I am trying to force user login first before see anything. Means I want my user to first login to view any single page, post or archive and only they can se FAQ page. I am trying with below code but problem is as soon as I loged in, its redirect me again to login page.

但是我的网站结构如下所示,并且我希望此代码能够正常工作...

However my site structure would be like below and in same manner I want this code to work...

// Force user to login on welcome
function my_force_login() {
global $post;

    if (is_single() || is_front_page() || is_page() && !is_page('login') && !is_user_logged_in()){ 
        auth_redirect(); 
    }   
}

欢迎登录屏幕(如facebook) -主页 -博客 -关于 -接触 -常见问题解答

Welcomd-Login screen (like facebook) -Home page -Blog -About -contact -FAQ

因此,我只允许访问者看到欢迎登录"屏幕和常见问题",联系"页面以查看要强制他们登录的网站的其余部分.

So I want to allow visitor only can see Welcome Login screen and FAQ, contact page to view rest of the site I want to force them to login..

我需要你们的大力帮助..提前谢谢..

I need great help of you people.. Thanks a lot in advance..

推荐答案

我认为您缺少括号:

if ( ( is_single() || is_front_page() || is_page() ) 
       && !is_page('login') && !is_user_logged_in()){ 
    auth_redirect(); 
} 

这篇关于Wordpress强制用户在查看任何网站内容之前先登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆