wordpress页面_强制登录以查看WordPress博客页面

wordpress页面

I was recently working on a private / "closed" website that featured WordPress.  User management is a must and content can only be seen if the user is logged in.  I was shocked to find that WordPress didn't provide an option to accomplish this task.  Luckily a quick snippet in the header of my template allowed me to force login to view content:

我最近在一个以WordPress为特色的私人/“封闭”网站上工作。 用户管理是必须的,只有在用户登录后才能看到内容。震惊地发现WordPress没有提供完成此任务的选项。 幸运的是,模板标题中有一个简短的摘要,使我可以强制登录以查看内容:


// Require login for site
get_currentuserinfo();
global $user_ID;
if ($user_ID == '') { 
	header('Location: /wp-login.php'); exit(); 
}


The get_currentuserinfo() function provides a huge object with information about the user.  We then look at the user_ID variable to see if the user's ID is defined -- if not, they aren't logged in and we should send them to the login page!

get_currentuserinfo()函数提供了一个巨大的对象,其中包含有关用户的信息。 然后,我们查看user_ID变量以查看是否定义了用户的ID-如果未定义,则他们没有登录,我们应该将其发送到登录页面!

Do remember that your header() calls must take place before any content is pushed to the page, so I recommend adding this content at the very top of your header.php file. There's also a WordPress plugin to accomplish this task.

请记住,您的header()调用必须在将任何内容推送到页面之前进行,因此我建议将此内容添加到header.php文件的最顶部。 还有一个WordPress插件可以完成此任务。

翻译自: https://davidwalsh.name/wordpress-force-login

wordpress页面

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值