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 siteget_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 to accomplish this task.
请记住,您的header()
调用必须在将任何内容推送到页面之前进行,因此我建议将此内容添加到header.php文件的最顶部。 还有一个可以完成此任务。
翻译自:
wordpress页面